简体   繁体   中英

How to get Dash to work with a Choropleth Plotly graph

I'm trying to get a Ploty choropleth map to display using Dash. I've tried updating Dash and Plotly by using the conda update --all and conda update dash in the anaconda prompt, but this hasn't fixed the issue. Below are links for the images of what the code produces for the fig.show() code and the Dash code.

在此处输入图像描述

Dash plotly graph that won't work:

在此处输入图像描述

Below is the code:

external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']

app = dash.Dash(__name__, external_stylesheets=external_stylesheets)


fig = px.choropleth(dt_rwly_stn, geojson=smh, color="ConfirmedCovidCases",
                    locations="CountyName", featureidkey="properties.CountyName",
                    projection="mercator",
                    color_continuous_scale= 'Reds',
                   )
fig.update_geos(fitbounds="locations", visible=False)
fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
fig.show() 

app.layout = html.Div(children=[
    html.H1(children='My First Dash'),

    html.Div(children='''
        Dash: A web application framework for Python.
    '''),

    dcc.Graph(
        id='example-graph1',
        figure=fig
    ),
])
                 
    
if __name__ == '__main__':
    app.run_server(debug=True, use_reloader=False)

Can anyone help me get the Plotly figure to display correctly using Dash?

I fixed the issue. I had to uninstall Anaconda as I had too many conflicting packages installed on my base environment. When I reinstalled it I made a new environment and only installed the packages I needed (ie conda install -c conda-forge dash and conda install -c conda-forge plotly . The code in question now works perfectly.

Dash Plotly Working

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM