Hello,
I am new to Dash and I got stuck with the following code:
import dash
from dash.dependencies import Input, Output
import dash_table
import dash_core_components as dcc
import dash_html_components as html
import pandas as pd
df = pd.read_csv(“data.csv”)
print(df)
app = dash.Dash(name)
app.layout = html.Div([
dash_table.DataTable(
id=‘datatable-interactivity’,
columns=[
{“name”: i, “id”: i, “deletable”: True, “selectable”: True} for i in df.columns
],
data=df.to_dict(‘records’),
editable=True,
filter_action=“native”,
sort_action=“native”,
sort_mode=“multi”,
column_selectable=“single”,
row_selectable=“multi”,
row_deletable=False,
selected_columns=,
selected_rows=,
page_action=“native”,
page_current= 0,
page_size= 5,
),
html.Div(id=‘datatable-interactivity-container’)
])
@app.callback(
Output(‘datatable-interactivity’, ‘style_data_conditional’),
[Input(‘datatable-interactivity’, ‘selected_columns’)]
)
def update_styles(selected_columns):
return [{
‘if’: { ‘column_id’: i },
‘background_color’: ‘#D2F3FF’
} for i in selected_columns]
@app.callback(
Output(‘datatable-interactivity-container’, “children”),
[Input(‘datatable-interactivity’, “derived_virtual_data”),
Input(‘datatable-interactivity’, “derived_virtual_selected_rows”)])
def update_graphs(rows, derived_virtual_selected_rows):
if derived_virtual_selected_rows is None:
derived_virtual_selected_rows = []
dff = df if rows is None else pd.DataFrame(rows)
colors = ['#7FDBFF' if i in derived_virtual_selected_rows else '#0074D9'
for i in range(len(dff))]
return [
dcc.Graph(
id=column,
figure={
"data": [
{
#"x": dff["country"],
"x": dff["code"],
"y": dff[column],
"type": "bar",
"marker": {"color": colors},
}
],
"layout": {
"xaxis": {"automargin": True,
"type": "category"},
"yaxis": {
"automargin": True,
"title": {"text": "age"},
#"type": "category"
},
"height": 500,
"margin": {"t": 20, "l": 20, "r": 20},
"sort": True
},
},
)
for column in ["time_delta"] if column in dff
]
if name == ‘main’:
app.run_server(debug=True)
The values shown in the graph look like this:
However, in reality the biggest value in the df column is not more than 15. Could you please advise me where I made a mistake?
Thanks you so much for your responses!!!