【发布时间】:2021-10-29 13:41:17
【问题描述】:
我一直坚持创建响应式图表:
有人知道我做错了什么吗?
# Build App
app = JupyterDash(__name__)
app.layout = html.Div([
html.H1("Index Scatterplot"),
dcc.Graph(id='graph'),
html.Label([
"constituent",
dcc.Dropdown(
id='constituent-dropdown', clearable=False,
value='AAPL.O', options=[
{'label': c, 'value': c}
for c in ['AAPL.O', 'AMZN.O', 'TSLA.O']
]),
])# Define callback to update graph
@app.callback(
Output('graph', 'figure'),
[Input("constituent-dropdown", "value")]
)
def update_figure(constituent):
return px.scatter(
data, x=".SPX", y=constituent, color="size",
color_continuous_scale='plasma',
render_mode="webgl", title="Return Distribution"
)# Run app and display result inline in the notebook
app.run_server(mode='inline', port=XXXX)
文件“C:xxxx.py”,第 21 行 def update_figure(成分): ^ SyntaxError: 无效语法
这是我使用的基本代码,用于更改颜色。
# Build App
app = JupyterDash(__name__)
app.layout = html.Div([
html.H1("Index Scatterplot"),
dcc.Graph(id='graph'),
html.Label([
"colorscale",
dcc.Dropdown(
id='colorscale-dropdown', clearable=False,
value='plasma', options=[
{'label': c, 'value': c}
for c in px.colors.named_colorscales()
])
]),
])# Define callback to update graph
@app.callback(
Output('graph', 'figure'),
[Input("colorscale-dropdown", "value")]
)
def update_figure(colorscale):
return px.scatter(
data, x=".SPX", y="AAPL.O", color="size",
color_continuous_scale=colorscale,
render_mode="webgl", title="Return Distribution"
)# Run app and display result inline in the notebook
app.run_server(mode='inline', port=XXXX)
感谢任何帮助。
【问题讨论】:
标签: plotly dashboard jupyterdash