Jan-31-2020, 10:16 PM
I want to create a web interface with a python srcipt in order to generate different graph from many CSV.
For that, I use pandas, plotly avec ipywidgets as librarys and Jupyter Notebook.
My first script allow to display a CSV according to the server and the date choose in the dropdowns :
![[Image: ss7u.png]](https://zupimages.net/up/20/05/ss7u.png)
My second script allow to display the CSV and trace a graph according to the FS choose in the dropdown. The script is :
![[Image: grch.png]](https://zupimages.net/up/20/05/grch.png)
So my question is : How to merge my two script to have the three dropdown at the same time in order to choose the server, the date and the FS needed ?
Thanks !
For that, I use pandas, plotly avec ipywidgets as librarys and Jupyter Notebook.
My first script allow to display a CSV according to the server and the date choose in the dropdowns :
from ipywidgets import interact, Dropdown from ipywidgets import widgets from IPython.display import display import plotly.express as px import pandas as pd from ipywidgets.embed import embed_minimal_html import sys import os ###################### Déclarations des widgets ###################### button = widgets.ToggleButton(description='click me') out = widgets.Output(layout=widgets.Layout(border = '1px solid black')) Server = os.listdir('/home/tim/Bureau/Servers/') ServerList = widgets.Dropdown(options = (Server)) Date = ['2019-10', '2019-11', '2019-12', '2020-01'] DateList = widgets.Dropdown(options = (Date)) @interact(ServersList = Server, DatesList = Date) def print_all(ServersList, DatesList): Test = os.listdir('/home/tim/Bureau/Servers'+ '/'+ ServersList+ '/'+ DatesList+'/') Path = os.path.join('/home/tim/Bureau/Servers'+ '/'+ ServersList+ '/'+ DatesList+'/' + str(Test).strip("[]").strip("''")) display(Path) df = pd.read_csv(Path) df.head() fig = px.line(df, x = 'Date', y = 'Total', title='DF command graph') fig.add_scatter(mode='markers+lines') display(df)This script works perfectly, the output is :
![[Image: ss7u.png]](https://zupimages.net/up/20/05/ss7u.png)
My second script allow to display the CSV and trace a graph according to the FS choose in the dropdown. The script is :
import ipywidgets as widgets from ipywidgets import interactive import pandas as pd import plotly.graph_objects as go import plotly.express as px df = pd.read_csv('/home/tim/Bureau/Servers/Server1/2019-10/Test1.txt') items = ['All']+sorted(df['FS'].unique().tolist()) def view(x=''): if x=='All': display(df) display(df[df['FS']==x]) fig = px.line(df[df['FS']==x], x = 'Date', y ='Total', title='DF command graph') #fig.add_scatter(x=df['Date'], y=df['Used']) fig.update_traces(mode='markers+lines') fig.show(); w = widgets.Dropdown(options=items) interactive(view, x=w)This script works perfectly too. The result is :
![[Image: grch.png]](https://zupimages.net/up/20/05/grch.png)
So my question is : How to merge my two script to have the three dropdown at the same time in order to choose the server, the date and the FS needed ?
Thanks !