I think I have figured out the basic mechanics of a multi-page app, but I am running into two error statements that have me a bit baffled when I try to design the page for a pie chart.
If I run it with the pie chart inside a layout div (“layout = html.Div([ ‘pie chart’ ])”), I receive the invalid Syntax error below.
If I run it not framed inside the same layout tag, the pie chart strangely pops up displayed in my browser, but I receive the “has no attribute layout” error message below.
I know I must frame the chart must inside the layout div in order to work within the multi-page app structure, but can anyone explain why I am receiving the syntax error indicating there is something wrong with attempt to set the variable name for px.pie? I cannot figure out what I am doing that would cause that error
And I receive the same error message if I try “df = pd.read_csv” or other alternate ways to read data into a figure like a pie chart. Is there an obvious explanation for this problem? Is it familiar to anyone and do you have a fix?
Many thanks for reviewing my question.
Right now, my code looks like this, based on a template from one of Adam’s videos, though I’ve tried a number of solutions. I don’t need a ton of bells and whistles. I just need the chart to read a two-column csv file, with the first column named “nutrients” and the second column named “percentages.”
df = pd.read_csv("pie_chart_data.csv") layout = html.Div([ pie = px.pie( data_frame=df, values='percentages', names='nutrients', color_discrete_sequence=["red","green","blue","orange"], #set marker colors # hover_data=['positive'], #values appear as extra data in the hover tooltip # custom_data=['total'], #values are extra data to be used in Dash callbacks title='Nutritional Profile', #figure title template='presentation', #'ggplot2', 'seaborn', 'simple_white', 'plotly', #'plotly_white', 'plotly_dark', 'presentation', #'xgridoff', 'ygridoff', 'gridon', 'none' width=800, #figure width in pixels height=600, #figure height in pixels hole=0, #represents the hole in middle of pie ) # pie_chart.update_traces(textposition='outside', textinfo='percent+label', # marker=dict(line=dict(color='#000000', width=4)), # pull=[0, 0, 0.2, 0], opacity=0.7, rotation=180) pio.show(pie) ])