破折号仪表板显示空白图

时间:2018-04-25 12:58:41

标签: python plotly dashboard plotly-dash

我想创建一个使用Dash显示指定位置的地图。我准备了一个剧本:

import dash
import dash_core_components as dcc
import dash_html_components as html
mapbox_access_token = 'pk.eyJ1IjoiYWxpc2hvYmVpcmkiLCJhIjoiY2ozYnM3YTUxMDAxeDMzcGNjbmZyMmplZiJ9.ZjmQ0C2MNs1AzEBC_Syadg'

app = dash.Dash()
server = app.server

app.layout = html.Div([
dcc.Graph(
    id='simple-map',
    figure=dict(
        data=dict(
            lat=[51.98799603],
            lon=[5.922999562],
            type='scattermapbox',
            marker=dict(size=5, color='white', opacity=0)
        ),
        layout=dict(
            mapbox=dict(
                layers=[],
                accesstoken=mapbox_access_token,
                style='light',
                center=dict(
                    lat=52.370216,
                    lon=-4.895168,
                ),
                pitch=0,
                zoom=2.5
            )
        )
    )
)

])

app.css.append_css({
'external_url': 'https://codepen.io/chriddyp/pen/bWLwgP.css'
})


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

然而,我得到了这个结果: result

我做错了什么?

1 个答案:

答案 0 :(得分:1)

解决方案总是比看上去简单。您必须在datamarker中添加括号。

import dash
import dash_core_components as dcc
import dash_html_components as html
mapbox_access_token = 'pk.eyJ1IjoiYWxpc2hvYmVpcmkiLCJhIjoiY2ozYnM3YTUxMDAxeDMzcGNjbmZyMmplZiJ9.ZjmQ0C2MNs1AzEBC_Syadg'

app = dash.Dash()
server = app.server

app.layout = html.Div([
dcc.Graph(
    id='simple-map',
    figure=dict(
        data=[dict(
            lat=[51.98799603],
            lon=[5.922999562],
            type='scattermapbox',
            marker=[dict(size=5, color='white', opacity=0)]
        )],
        layout=dict(
            mapbox=dict(
                layers=[],
                accesstoken=mapbox_access_token,
                style='light',
                center=dict(
                    lat=52.370216,
                    lon=-4.895168,
                ),
                pitch=0,
                zoom=2.5
            )
        )
    )
)

])

app.css.append_css({
'external_url': 'https://codepen.io/chriddyp/pen/bWLwgP.css'
})


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

结果是: correct result