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 CSV looks like :
Date,FS,Total,Used,Mount
2020-01-25-12-00,/dev/hd1/,350,300,/dev/mount1
2020-01-25-18-00,/dev/hd2/,370,320,/dev/mount2
2020-01-26-06-00,/dev/hd3/,395,350,/dev/mount3
2020-01-26-12-00,/dev/hd1/,350,300,/dev/mount1
2020-01-26-18-00,/dev/hd2/,370,320,/dev/mount2
2020-01-27-06-00,/dev/hd3/,395,350,/dev/mount3
2020-01-27-12-00,/dev/hd1/,350,300,/dev/mount1
2020-01-27-18-00,/dev/hd2/,370,320,/dev/mount2
2020-01-28-06-00,/dev/hd3/,395,350,/dev/mount3
2020-01-28-12-00,/dev/hd1/,350,300,/dev/mount1
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 :
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 :
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 !