I've recently start working with Dash in python and still have the habit of putting semicolon at the end of line, I know there is supposedly no difference between a newline and a semicolon in python but after having done my first @callback()
function I put one before the def of the update()
function and a SyntaxError: invalid syntax
appeared. So is there a real, even if it is tiny, difference between the two?
(here my code)
from dash import Dash, html, dcc, callback, Output, Input, dash_table
import dash_daq as daq
import plotly.express as px
import pandas as pd
from plotly.graph_objs._figure import Figure
df:pd.DataFrame = pd.read_csv("mydata.csv");
app:Dash = Dash();
app.config.suppress_callback_exceptions = True;
app.layout = [
html.Div(
id ='parent-div',
dcc.Graph('section-graph'),
dcc.RadioItems(['ALL', 'Groupe 1', 'Groupe 2', 'Groupe 3'], 'ALL', id='section-choice', inline=True),
)
]
@callback(
Output('section-graph', 'figure'),
Input('section-choice', 'value')
); #this semicolon cause a SyntaxError: invalid syntax
def update_section_graph(value:str):
if value == 'ALL':
return px.pie(df,
'Section',
title='Section',
hole=.3,
labels='Section',
color='Section',
color_discrete_map={'AR': '#be5050', 'GCG': '#5fac4a', 'GC': '#e64509',
'GM': '#e0d429', 'EL': '#ffc300', 'IN': '#e293ee',
'SV': '#ee931b', 'MA': '#6ae255', 'MT': '#ece365',
'PH': '#47bd59', 'MX': '#c2b60d', 'SIE': '#db7171',
'SC': '#f2b2fd'}
).update_traces(textinfo='percent+label').update_layout(showlegend=False);
return px.pie(df.loc[df['Groupe'] == value],
'Section',
title='Section',
hole=.3,
labels='Section',
color='Section',
color_discrete_map={'AR': '#be5050', 'GCG': '#5fac4a', 'GC': '#e64509',
'GM': '#e0d429', 'EL': '#ffc300', 'IN': '#e293ee',
'SV': '#ee931b', 'MA': '#6ae255', 'MT': '#ece365',
'PH': '#47bd59', 'MX': '#c2b60d', 'SIE': '#db7171',
'SC': '#f2b2fd'}
).update_traces(textinfo='percent+label').update_layout(showlegend=False);