Hi,
I would like to ask you for a help.
Issue: Rectangle shape doesn’t show when starting the app. It comes only after refreshing the app.
Thanks a lot
OS: Big Sur 11.5
Browser: Safari
Python: 3.9
dash: 1.21.0
dash-bootstrap-components: 0.12.2
dash-core-components: 1.17.1
dash-html-components: 1.1.4
Plotly: 5.0.0
import pandas as pd
import dash
import dash_core_components as dcc
import dash_html_components as html
import dash_bootstrap_components as dbc
from dash.dependencies import Input, Output
import plotly.graph_objects as go
from plotly.subplots import make_subplots
checklist = dbc.Checklist(
id='checklist',
options=[
{'label': 'Y1', 'value': 'Y1'},
{'label': 'Y2', 'value': 'Y2'},
],
value=['Y1'],
inline=True,
)
iv_graph = dbc.Spinner(
color="primary",
children=[
html.Div(
dcc.Graph(
id='graph',
)
),
]
)
app = dash.Dash(__name__, external_stylesheets=[dbc.themes.SKETCHY])
app.layout = dbc.Container(
[
dbc.Row([
dbc.Col(checklist),
]),
dbc.Row([
dbc.Col(iv_graph),
]),
],
)
#--------------graphs-------------------
@app.callback(
Output('graph', 'figure'),
Input('checklist', 'value'),
)
def update_Graph_figure(checklist):
data = [[3000, 80, 20], [4000, 60, 30], [5000, 70, 10], [6000, 40, 50], [7000, 50, 30], [8000, 60, 40]]
iv_ec = pd.DataFrame(data, columns = ['X', 'Y1', 'Y2'])
fig = make_subplots(specs=[[{"secondary_y": True}]])
if 'Y1' in checklist:
fig.add_trace(go.Scatter(
x=iv_ec["X"],
y=iv_ec["Y1"],
mode='lines',
line_width = 4,
marker_color='black',
opacity=1),
secondary_y=False,
)
if 'Y2' in checklist:
fig.add_trace(go.Scatter(
x=iv_ec["X"],
y=iv_ec["Y2"],
mode='lines',
line_width = 2,
marker_color='gray',
opacity=1),
secondary_y=False,
)
fig.add_vrect(
x0=4000, x1=6000,
line_width=0,
fillcolor="red",
opacity = 0.8,
)
return fig
if __name__ == "__main__":
app.run_server(host='0.0.0.0', port='8050', debug=False,)