[英]TypeError: __init__() got multiple values for argument 'marks'
I'm getting the following error of TypeError: __init__() got multiple values for argument 'marks'
for the code below and I'm not sure how to best fix it.我收到以下
TypeError: __init__() got multiple values for argument 'marks'
我不确定如何最好地修复它。 i know its referring to the marks however I'm unsure how this needs to be changed?我知道它指的是标记但是我不确定这需要如何改变? Thanks in advance
提前致谢
app = dash.Dash(__name__)
app.title = "Performance"
dfsites = pd.read_csv("3msites.csv")
colors = {
"background": "#011833",
"text": "#7FDBFF"
} #Dictionary of colors to use later
fig1 = px.scatter(dfsites, x='Spend',y='CPA',
size= 'Conversions', color='Campaign', hover_name='Site',
log_x=True)
)
app.layout = html.Div(children=[
html.Div([
html.H4(children='Sites', style={"textAlign": "center"}),
dcc.Graph(
id='site-graph',
figure=fig1),
dcc.Slider(
dfsites['Month'].min(),
dfsites['Month'].max(),
step=None,
value=dfsites['Month'].min(),
marks={str(Month) for Month in dfsites['Month'].unique()},
id='Month-slider'
)
]),
])
@app.callback(
Output('site-graph', 'figure'),
Input('Month-slider', 'value'))
def update_figure(selected_Month):
filtered_dfsites = dfsites[dfsites.Month == selected_Month]
fig1.update_layout(transition_duration=500)
return fig1
if __name__ == '__main__':
app.run_server(debug=True)
Traceback error:回溯错误:
Traceback (most recent call last):
File "/Users/~/Dash.py", line 94, in <module>
dcc.Slider(
File "/Users/~/opt/anaconda3/lib/python3.8/site-packages/dash/development/base_component.py", line 366, in wrapper
return func(*args, **kwargs)
TypeError: __init__() got multiple values for argument 'marks'
I experienced a similar error with the Dropdown component:我在使用 Dropdown 组件时遇到了类似的错误:
__init__() got multiple values for argument 'id'
In my case, I had to update dash:就我而言,我必须更新破折号:
pip3 install dash --upgrade
Moreover, I had to update the component configuration like this:此外,我必须像这样更新组件配置:
dcc.Dropdown(
options=['New York City', 'Montreal', 'San Francisco'],
value='Montreal'
)
(refer to the component reference documentation here: https://dash.plotly.com/dash-core-components ) (请参阅此处的组件参考文档: https ://dash.plotly.com/dash-core-components)
The argument you're passing to marks
needs to be a dictionary.您传递给
marks
的参数必须是字典。
{str(Month) for Month in dfsites['Month'].unique()}
is a set. {str(Month) for Month in dfsites['Month'].unique()}
是一个集合。
You can create a dictionary comprehension with {Month: str(Month) for Month in dfsites['Month'].unique()}
mapping each Month to its string representation您可以使用
{Month: str(Month) for Month in dfsites['Month'].unique()}
创建字典理解,将每个月映射到其字符串表示
Update your slider code to something like below:将您的 slider 代码更新为如下所示:
dcc.Slider(
min=dfsites['Month'].min(),
max=dfsites['Month'].max(),
step=None,
value=dfsites['Month'].min(),
marks={str(Month):str(Month) for Month in dfsites['Month'].unique()},
id='Month-slider'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.