Hi, I am new to plotly dash.
I am running the code below:
app = dash.Dash(
__name__,
meta_tags=[{"name": "viewport", "content": "width=device-width, initial-scale=1"}],
)
server = app.server
def build_banner(header,hd_subtitle):
return html.Div(
id="banner",
className="banner",
children=[
html.Div(
id="banner-text",
children=[
html.H5(str(header)),
html.H6(str(hd_subtitle)),
],
),
html.Div(
id="banner-logo",
children=[
#html.A([
# html.Button(
# id="learn-more-button", children="LEARN MORE", n_clicks=0
#),
#],href='https://www.google.com'),
html.Button(
id="learn-more-button", children="LEARN MORE", n_clicks=0
),
#html.Button(
# id="learn-more-button", children="LEARN MORE", n_clicks=0
#),
html.A([
html.Img(id="logo",src=app.get_asset_url("logo.png")),
],href='https://www.google.com'),
],
),
],
)
def generate_section_banner(title):
return html.Div(className="section-banner", children=title)
def build_top_panel():
return html.Div(
id="top-section-container",
className="row",
children=[
# Metrics summary
html.Div(
id="summary-lol1",
className="six columns",
children=[
generate_section_banner("Customer Base"),
dcc.Graph(id='histinst'),
],
),
html.Div(
id="summary-lol2",
className="six columns",
children=[
generate_section_banner("Service Visit Booking"),
dcc.Graph(id="histsr"),
],
),
],
)
def build_tab():
return [
html.Div(
id="status-container",
children=[
html.Div(id='none',children=[],style={'display': 'none'}),
html.Div(
id="graphs-container",
className="row",
children=[
build_top_panel(),
html.Br(),
#build_chart_panel()
],
),
],
),
]
app.layout = html.Div(
id="big-app-container",
children = [
build_banner("sky","Introducing Fluid Viewing"),
html.Hr(),
html.Div(
id="app-container",
children=[
build_tab(),
],
),
],
)
per = df['master_mesh_olive_post_code_test.first_install_date'].dt.to_period("M")
@app.callback(
[Output('histinst', 'figure')],
[Input('none', 'children')]
)
def update_histogram_install(none):
df_install = pd.DataFrame({'count' : df.groupby(per).size()}).reset_index()
trace = go.Bar(x=df_install['master_mesh_olive_post_code_test.first_install_date'].astype(str),
y=df_install['count'], hoverinfo="x")
return {
'data': trace,
'layout': go.Layout(title='Customer Base Number',
hovermode="closest",
xaxis={'title': "Dates", 'titlefont': {'color': 'black', 'size': 14},
'tickfont': {'size': 9, 'color': 'black'}},
yaxis={'title': "Number of Customers", 'titlefont': {'color': 'black', 'size': 14, },
'tickfont': {'color': 'black'}})}
@app.callback(
[Output('histsr', 'figure')],
[Input('none', 'children')]
)
def update_histogram_service(none):
df_service = df.groupby(per).agg({"master_mesh_olive_post_code_test.number_of_service_visit_booked": "sum"}).reset_index()
trace = go.Bar(x=df_service['master_mesh_olive_post_code_test.first_install_date'].astype(str),
y=df_service['master_mesh_olive_post_code_test.number_of_service_visit_booked'], hoverinfo="x")
return {
'data': trace,
'layout': go.Layout(title='Service Booking',
hovermode="closest",
xaxis={'title': "Dates", 'titlefont': {'color': 'black', 'size': 14},
'tickfont': {'size': 9, 'color': 'black'}},
yaxis={'title': "Number of Services Booked", 'titlefont': {'color': 'black', 'size': 14, },
'tickfont': {'color': 'black'}})}
I keep getting the error:
106
107 @app.callback(
ā> 108 [Output(āhistinstā, āfigureā)],
109 )
110 def update_histogram_install():
ā¦
AttributeError: āDivā object has no attribute ākeysā
Can someone please guide me on this one?
In place of df the dataframe any random value can be considered.