首页 > 解决方案 > 为什么 plotly 的配置在 dash 中不起作用?

问题描述

当我使用fig.show时,会显示模式栏按钮,但是当我尝试对破折号执行相同操作时,它不起作用。我尝试了很多选择,但它似乎不起作用。文档也不完整。顺便说一下,这些是内置按钮,而不是自定义按钮。

我在教程中看到了这个:

fig.show(config={'modeBarButtonsToAdd':['drawline',
                                        'drawopenpath',
                                        'drawclosedpath',
                                        'drawcircle',
                                        'drawrect',
                                        'eraseshape'
                                       ]})

然后,我尝试在 dash 而不是 dash 中输入相同的内容fig.show,但它不起作用!

app.layout = html.Div([
    dcc.Graph(
        id='mainPlot',
        figure=fig,
        config={'modeBarButtonsToAdd':['drawline',
                                        'drawopenpath',
                                        'drawclosedpath',
                                        'drawcircle',
                                        'drawrect',
                                        'eraseshape'
                                       ]}
    )
])

这是 MWE:我想通过and not传递configwith 。它适用于按钮是内置的,但不适用于配置传递,因为我收到错误说按钮需要使用名称、单击功能等进行定义,并且被视为自定义按钮而不是启用内置按钮.modeBarButtonsToAddconfigapp.layoutfig.showfig.showapp.layout

import dash
import dash_core_components as dcc
import dash_html_components as html

app = dash.Dash()

app.layout = html.Div(children=[
    dcc.Graph(
        id='example-graph',
        figure={
            'data': [
                {'x': [1, 2, 3], 'y': [4, 1, 2], 'type': 'bar', 'name': 'SF'},
                {'x': [1, 2, 3], 'y': [2, 4, 5], 'type': 'bar', 'name': u'Montréal'},
            ],
            'layout': {
                'title': 'Dash Data Visualization'
            }
        }
    )
])

if __name__ == '__main__':
    app.run_server(debug=True)

标签: plotly-dash

解决方案


安装最新版本的 dash 应该可以解决您的问题。


推荐阅读