Hi everyone. I am new to python, I want to create dashboards. I have some HTML/CSS experience so that helps but I am still very confused on callbacks and what/what not to put on Output/Input and the following function + the data it should return.
What I want:
I essentially want one main chart, and based off the radioItem a person selects (BTC or ETH) the main chart will update based on price from the past year. Eventually, I’d like to add more charts, newsfeeds etc that updates as well based off the currency selected in the radioItem.
I took a crack at it, here is my code:
Edited: updated code
import dash_core_components as dcc
import dash_html_components as html
import plotly.graph_objs as go
from dash.dependencies import Input, Output
import pandas as pd
import numpy as np
app = dash.Dash()
btc_data = pd.read_csv('BTC-CAD.csv', parse_dates=True)
app.layout = html.Div([
html.H1('Test'),
html.Div([
dcc.RadioItems(
id='radio-1',
options=[
{'label': 'Bitcoin', 'value': 'BTC'},
{'label': 'Ethereum', 'value': 'ETC'},
],
value='BTC'
)
], style={'width': '48%', 'display': 'inline-block'}
),
html.Div([
dcc.Graph(
id = 'scatter-chart-1',
figure = {
'data' : [
go.Scatter(
x = btc_data.Date,
y = btc_data.Close,
mode = 'lines'
)
],
'layout': go.Layout(
title = 'BTC - CAD Prices',
xaxis = {'title' : 'Date'},
yaxis = {'title' : 'Price (Cad)'}
)
}
)
])
])
# call back to update main graph
@app.callback(
dash.dependencies.Output('scatter-chart-1', 'figure'),
[dash.dependencies.Input('radio-1', 'value')])
def update_page(radio):
eth_data = pd.read_csv('ETH-CAD.csv', parse_dates=True)
if value == 'BTC':
figure = {
'data' : [
go.Scatter(
x = btc_data.Date,
y = btc_data.Close,
mode = 'lines'
)
],
'layout': go.Layout(
title = 'BTC - CAD Prices',
xaxis = {'title' : 'Date'},
yaxis = {'title' : 'Price (Cad)'}
)
}
return figure
if value == 'ETH':
figure = {
'data': [
go.Scatter(
x = eth_data.Date,
y = eth_data.Close,
mode = 'lines'
)
]
}
return figure
if __name__ == '__main__':
app.run_server(port=4050)```
any help is appreciated!