Reputation: 129
I'm trying to generate a scattermapbox using dash and plotly, when I specify a symbol (e.g. "square") inside the marker, it doesn't render when the map is generated. I'm using a callback function and I tried several symbols, none of which worked, but the circle marker. Is there something obvious that I'm missing? Here is a minimal example, to run it you will need a mapbox token.
import dash
import dash_core_components as dcc
import dash_html_components as html
import plotly.graph_objs as go
import datetime as dt
app = dash.Dash()
mapbox_access_token = 'YOUR_MAPBOX_TOKEN_HERE'
app.layout = html.Div(children=[
html.H1('Dashboard'),
dcc.DatePickerRange(id='fecha',
start_date=dt.datetime.today() - dt.timedelta(days=30),
end_date=dt.datetime.today()
),
html.Center(dcc.Graph(
id='mapa',
figure={
'data': [
go.Scattermapbox(
lat=[],
lon=[],
)
],
'layout': go.Layout(
autosize=False,
width=1300,
height=800,
hovermode='closest',
showlegend=False,
mapbox=dict(
accesstoken=mapbox_access_token,
bearing=0,
center=dict(
lat=-32,
lon=-70
),
pitch=0,
zoom=5,
),
)
})
,)
])
@app.callback(
dash.dependencies.Output('mapa', 'figure'),
[dash.dependencies.Input('fecha', 'start_date'),
dash.dependencies.Input('fecha', 'end_date')
])
def update_graph(inicio,fin):
Data = [go.Scattermapbox(
name='square',
lat=[-31,-30],
lon=[-71,-71],
marker = dict(
symbol='square',
size = 8,
opacity = 0.8,
color='grey'
),
text = np.array(['square1','square2'])),
go.Scattermapbox(
name='circle',
lat=[-31,-30],
lon=[-72,-72],
marker = dict(
symbol='circle',
size = 8,
opacity = 0.8,
color='grey'
),
text = ['circle1','circle2'])]
figure={
'data': Data,
'layout': go.Layout(
title='Visitas',
autosize=False,
width=1300,
height=800,
hovermode='closest',
showlegend=True,
mapbox=dict(
accesstoken=mapbox_access_token,
bearing=0,
center=dict(
lat=-30.5,
lon=-72
),
pitch=0,
zoom=5,
),
)
}
return figure
if __name__ == '__main__':
app.run_server(host= '0.0.0.0',port=9999)
I tried making the same mapbox without dash (i.e. just plotly), and it failed again, so it's not a dash problem, here is how I made the map with plotly (for this you'll need a plotly account):
import plotly.graph_objs as go
import plotly.plotly as py
mapbox_access_token = 'YOUR_TOKEN_HERE'
Data = [go.Scattermapbox(
name='square',
lat=[-31,-30],
lon=[-71,-71],
marker = dict(
symbol='square',
size = 8,
opacity = 0.8,
color='grey'
),
text = ['square1','square2']),
go.Scattermapbox(
name='circle',
lat=[-31,-30],
lon=[-72,-72],
marker = dict(
symbol='circle',
size = 8,
opacity = 0.8,
color='grey'
),
text = ['circle1','circle2'])]
figure={
'data': Data,
'layout': go.Layout(
title='Visitas',
autosize=False,
width=1300,
height=800,
hovermode='closest',
showlegend=True,
mapbox=dict(
accesstoken=mapbox_access_token,
bearing=0,
center=dict(
lat=-30.5,
lon=-72
),
pitch=0,
zoom=5,
),
)
}
py.iplot(figure, filename='Broken fig')
Thanks in advance, I still don't know if I'm missing something obvious.
Upvotes: 5
Views: 6419
Reputation: 129
I found that the problem was mainly by 2 things:
I also opened a github issue where you can find a bit more info github issue
Upvotes: 3