破折号仪表板显示空白图
Dash dashboard shows blank figure
我想使用 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)
但是,我得到了这个结果:
我做错了什么?
解决方案总是比看起来简单。您必须向 data
和 marker
添加方括号。
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)
结果是:
我想使用 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)
但是,我得到了这个结果:
我做错了什么?
解决方案总是比看起来简单。您必须向 data
和 marker
添加方括号。
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)
结果是: