Python Dash中RangeSlider组件回调出现slidevalue不支持等错误如何解决?
问题修复方案
核心错误点1:组件属性与id配置错误
- dcc.RangeSlider组件的取值属性为
value,不存在slidevalue属性,你在回调Input项中填写的属性名错误,是第一个报错的直接原因 - 布局代码中RangeSlider的id误加了Markdown加粗星号,实际组件id不能包含特殊符号,需去掉星号改为
id='ageslider'
修正后的布局代码片段
dbc.Col([ html.Div(id='Title_Slider', children='''Milo na ena LOLA''', style={'margin-bottom':'50px', 'text-align':'center'}), html.Div(dcc.RangeSlider(id='ageslider',min=18,max=60,step=1,value=[18,60], marks={str(Age): str(Age) for Age in data.Age.unique()} ), style={'width': '100%', 'padding': '0px 20px 20px 20px'}),
核心错误点2:回调参数写法错误
第二个'NoneType' object is not subscriptable报错是第一个错误的衍生问题:因为属性名填写错误,回调无法读取到滑块的有效取值,拿到的返回值为None,同时你错误使用双星号**vage来接收位置参数,尝试对None取下标就触发了类型错误。
修正后的回调代码
@app.callback( Output('bar-1', 'figure'), Input('dropdown1','value'), Input('ageslider','value'), Input('binat','bivalue')) def update_line_chart(filter_metric, vage, bi_value): v_min = vage[0] v_max = vage[1] # age_filter is a custom func that works datac_ = age_filter(data, v_min, v_max) a=datac_.groupby([filter_metric,'Attrition']).apply(lambda x:x[filter_metric].count()).reset_index(name='Counts') fig = px.line(a, x=filter_metric, y="Counts", color='Attrition',markers=True,height=500, width=700) fig.update_layout(plot_bgcolor=colors['background'],paper_bgcolor=colors['background'], font_color=colors['text']) return fig
修改完以上三点即可解决所有报错。
内容的提问来源于stack exchange,提问作者Christos Logaras
相关产品推荐
相关产品推荐

