Show map tile even when dataframe is empty

Hey guys,

I’m trying to show map (open-street-map) even when I have empty dataframe but I don’t know how. When I have empty dataframe the map backgroud (tile) is missing and I got blank axis.

Not empty dataframe

Empty dataframe

I would like to keep the map background and just have no markers on map. Can you help me out? Thanks!

# --------------------
# Layout
app.layout = html.Div([
    dcc.Checklist(id='technology',
        options=[
            {'label': 'Sypač', 'value': 1},
            {'label': 'Sekačka', 'value': 2},
            {'label': 'Samosběr', 'value': 3},
            {'label': 'Kropice', 'value': 4},
            {'label': 'Valník', 'value': 5},
            {'label': 'Nosič kontejnerů', 'value': 6},
            {'label': 'Ostatní', 'value': 7}
        ],
        value=[1, 2, 3, 4, 5, 6, 7],
        labelStyle={'display': 'block'}
        ),

    dcc.Graph(id='susuk_map')
])

# --------------------
# Callbacks
@app.callback(
    Output(component_id='susuk_map', component_property='figure'),
    [Input(component_id='technology', component_property='value')]
    )

def update_graph(option_technology):
    print(option_technology)
    print(type(option_technology))

    dff = df[df["technology"].isin(option_technology)]
    print(dff)

    map = px.scatter_mapbox(dff, lat="lat", lon="lon", hover_name="rz", hover_data=["type", "ignition", "gpsSpeed"], color_discrete_sequence=["red"], zoom=8, height=800)
    map.update_layout(mapbox_style="open-street-map", margin={"r":0,"t":0,"l":0,"b":0})
    map['layout']['uirevision'] = 'foo'

    return map

# --------------------
if __name__ == '__main__':
    app.run_server(debug=True)
1 Like