【发布时间】:2019-03-05 15:45:31
【问题描述】:
您好,我目前正在尝试在 python dash 上构建散点图,我可以在其中将下拉列表(由不同的列名组成)连接到散点图。因此,当我更改下拉列表的值时,散点图将根据下拉列表的值显示不同的值。但是,我的问题是列名本质上是一个字符串,下拉列表包含这些值的字典,因此很难通过。这是我现在拥有的代码:
html.Div([dcc.Dropdown(
id='mood',
options=[
{'label': 'Positive', 'value': 'Positive'},
{'label': 'Negative', 'value': 'Negative'},
{'label': 'Compound', 'value': 'Compound'}],
value='Compound')], style={'width':'15%'}
),
html.Div([
dcc.Graph(id='linear')]),
html.Div([
dcc.Graph(id='linear2')])
])
@app.callback(
dash.dependencies.Output('linear','figure'),
[dash.dependencies.Input('mood','value')])
def update_graph(mood_name):
y=file.get(column) ==mood_name]
scatter=go.scatter(y=y,marker=dict(
color='rgb(0,191,255)', # code for sky blue 0,191,255
line=dict(
color='rgb(8,48,107)',
width=1.5,
)),opacity=0.6,name='Sentiment')
layout=go.Layout(xaxis={'title': 'Tweets'},
yaxis={'title': 'Polarity'},
title= 'Tweets',
hovermode='closest')
return {'data':[scatter],
'layout':[layout]}
def update graph 函数是我在传递这些列名(正、负和复合)时遇到问题的地方。任何帮助将不胜感激,谢谢!
【问题讨论】:
标签: python function callback plotly plotly-dash