Dash with plotly bar and two cvs files

hi all,
i’m able to import a csv file and make a graph bar with dash

but how with two different csv files, the 2 files have two columns like that :
2021-12-21,40
2021-12-22,55

i need two bar graph with the data of the two files… have you simple example ?

regards

HI @defaliz
Welcome to the Dash community.

There are a couple of ways of doing this. For example you can import the two csv files as two different dataframes (df and df1.
Then, use one dataframe to create the first bar graph and the second dataframe to create the second bar graph.
If you need to create a bar graph with both dataframes, then you can use pandas.DataFrame.merge to merge the dataframe and build a graph out of it.

Good luck and keep it up!

Hi Adam,
thank a lot for your reply…
as you said i try some things and i found a solution with add_trace, following an extract of my script…
it work like a charm…
another question : i use dash, and i launch my script like that :

nohup python3 myscript.py &

but how can i renew graph automaticaly when new data are provide ?
thanks again and have a happy christmas !

df1 = pd.read_csv('logs_atelier.csv')
df2 = pd.read_csv('logs_pzem_atelier.csv')
# Sort both by 'Date'
df1_sorted = df1.sort_values(by='Date')
df2_sorted = df2.sort_values(by='Date')
fig = go.Figure()
fig.add_trace(
    go.Bar(
        x=df1_sorted['Date'],
        y=df1_sorted['Victron'],
        name="Victron atelier"
    ))
fig.add_trace(
    go.Bar(
        x=df1_sorted['Date'],
        y=df2_sorted['Pzem17'],
        name="Pzem17 atelier"
    ))
app = dash.Dash()
app.layout = html.Div([
    dcc.Graph(figure=fig)
])

Screenshot 2021-12-25 at 11-10-01 Dash

HI @defaliz
to renew graph data, you need to upload the new CSV sheets. If you want something more automatic, you would need to extract your data from an online database (MySQL, PostgreSQL, etc.) or connect to an API where the data is located. Another thing you could do, is allow the user to upload a csv sheet to the app and have it create some graphs on the spot. You would need to use the dcc.upload component for that.