Quantcast
Channel: 🎛️ Dash - Plotly Community Forum
Viewing all articles
Browse latest Browse all 6271

Help using custom GeoJson Files

$
0
0

Currently I’m working on an App to display stats in Mexico, everything is going fine but, i have an issue loading GeoJson files within Dash, my choroplethmapbox works fine in Jupyter and even when I usde fig.show(), inside a callback it works just fine.

Amy help on this issue will be greatly appreciated.

This is te result of runnig fig.show()in the callback

This is the same map in dash

Here’s a snippet of my code

app.layout = html.Div([
dcc.Slider(id='year-slider',
               min=2012,
               max=2020,
               marks={x: {'label': str(x)} for x in range(2012,2021)},
               value=2012,
            ),
            dcc.Graph(id="choropleth")
])

This is the callback I’m trying to implement

@app.callback(
    Output('choropleth', 'figure'),
    [Input('year-slider', 'value')])

def display_choropleth(selected_year):

#load polygons
    with open("states.json", encoding="utf8") as f:
        counties = json.load(f)

fig = go.Figure(px.choropleth_mapbox(dff, geojson=counties, featureidkey='properties.state_code',
                           locations='unique_values', color='counts',
                           color_continuous_scale="Viridis",
                           mapbox_style="carto-positron",
                           zoom=4.5, center = {"lat":23.634501 , "lon": -102.552784},
                           opacity=1,
                           labels={'counts':'Deceased'},
                           hover_name="unique_values"))
    accesstoken = token
    fig.update_layout(mapbox_style="dark", mapbox_accesstoken=accesstoken)
    fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0},height=700)
    fig.update_layout(coloraxis=dict(colorbar_thickness=30, colorbar_bgcolor='#1A1A1A',colorbar_tickfont_color='#fff',colorbar_title_font_color='#fff',colorbar_xanchor="right"))
    fig.show()
    return fig  

Please help.

2 posts - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 6271

Latest Images

Trending Articles



Latest Images