Two question about Plotly : How to create graph from many csv files and add button?

Hello !

I’m here because I’m a beginner with python and plotly and I need some help.

First question :

I’ve created a CGI that allow me to display graph from many csv.

To do that, I use Gnuplot. This is my script :

set terminal png truecolor size 1950, 650  background rgb "#eff1f0"
set output "/xxx/xxx/xxx/xxx/test.png"
set datafile separator ';'

set size ratio 0.2
set bmargin at screen 0.2
unset key
set datafile separator ";"
set ylabel " MB BLOCK " font ",10" offset -1,0
set xlabel font ",10"
set xtics rotate by 45  offset -0.8,-9,-1.8


plot "/var/xxx/xxx/xxx/xxx/xxx/2020-01/Serveur1/fs1.txt" using 3:xtic(1) title column(2) with linespoints linewidth 2 pointtype 7 pointsize 1.5, \
   "/var/xxx/xxx/xxx/xxx/xxx/2020-01/Serveur1/fs2.txt" using 3:xtic(1) title column(2) with linespoints linewidth 2 pointtype 7 pointsize 1.5, \
   "/var/xxx/xxx/xxx/xxx/xxx/2020-01/Serveur1/fs3.txt" using 3:xtic(1) title column(2) with linespoints linewidth 2 pointtype 7 pointsize 1.5, \
   "/var/xxx/xxx/xxx/xxx/xxx/2020-01/Serveur1/fs4.txt" using 3:xtic(1) title column(2) with linespoints linewidth 2 pointtype 7 pointsize 1.5, \
   "/var/xxx/xxx/xxx/xxx/xxx/2020-01/Serveur1/fs5.txt" using 3:xtic(1) title column(2) with linespoints linewidth 2 pointtype 7 pointsize 1.5, \
   "/var/xxx/xxx/xxx/xxx/xxx/2020-01/Serveur1/fs6.txt" using 3:xtic(1) title column(2) with linespoints linewidth 2 pointtype 7 pointsize 1.5, \
   "/var/xxx/xxx/xxx/xxx/xxx/2020-01/Serveur1/fs7.txt" using 3:xtic(1) title column(2) with linespoints linewidth 2 pointtype 7 pointsize 1.5, \
   "/var/xxx/xxx/xxx/xxx/xxx/2020-01/Serveur1/fs8.txt" using 3:xtic(1) title column(2) with linespoints linewidth 2 pointtype 7 pointsize 1.5, \
   "/var/xxx/xxx/xxx/xxx/xxx/2020-01/Serveur1/fs9.txt" using 3:xtic(1) title column(2) with linespoints linewidth 2 pointtype 7 pointsize 1.5

With the lastest plot lines of this script, I’m able to trace a curve from many csv… With pltoly, I use this script :

import pandas as pd
import plotly.express as px


df = pd.read_csv('Desktop/test.csv')
df.head()

df2 = pd.read_csv('Desktop/test2.csv')
df.head()

fig = px.line(df, x = 'Date', y ='Total', title='DF command graph')
fig.add_scatter(x=df2['Date'], y =df2['Free'] )

fig.update_traces(mode='markers+lines')

fig.show()

But I’ve 25 csv… Do I have to create a df variable for each csv and add a fig.add_scatter for each new csv ? Du you know an other way ?

My second question is :

I see that is possible to add some buttons to interact with the graph… I would like to add one button on my graph which allow to trace a trendline when I click on it but I don’t know how to do that…

Just to show me how to create a button, Could you explain to me how to create a simple button which display " Hello world " ?

Thank you !