Cannot plot go.Choropleth inside dcc.Graph

Hi, I’m trying to plot a go.Choropleth map inside a figure fed to dcc.Graph.

Unfortunately, the map is not showed and I’m faced with a grid kind of graph typically used for scatter plots (as per the image below).

I’m running Dash 1.12.0 with Pyplot 4.7.1 (the most up-to-date versions in Python3 pip). The map is displayed correctly when using map_fig.show().

Am I missing something? Is there some problem with the current version of dash?
Thank you

def plot_country_map():

	df = pd.read_csv('countries.csv')
	map_fig = go.Figure(data=go.Choropleth(
		locations = df['country_codes'],
		z = df['country_measurements'],
		text = df['country_names'],
		colorscale = 'Reds',
		autocolorscale=False,
		marker_line_color='darkgray',
		marker_line_width=0.5,
		colorbar_title = 'Measurements',
	))

	map_fig.update_layout(
		title_text = 'Measured Countries',
		geo = dict(
			resolution = 50,
			projection_type = "miller",
			showcoastlines=False,
			lataxis = dict(
				range = [-60, 90], #Clip Antarctica
			),
		)
	)

	map_plot = dcc.Graph(id='country_maps',figure=map_fig)

	return map_plot

Hi @dmbb93
Do you have an app.layout section in your code?

Hi @adamschroeder! I do have one, yes.

The layout for this page is inside html.Div(getHomepage())

where getHomepage() is:

def getHomepage():

	elems = [
		html.P("Here is the map"),
		plot_country_map(),
	]
	return elems

I have a few different pages using dcc.Graph() to plot scatter and bar plots, with a similar layout organization. However, it seems like dcc.Graph() is not updating the figure field when I use go.Choropleth().

Thank you!

that’s weird. If you are using dcc.grpah() to plot scatter and bar plots, then it should plot go.choropleth(). Have you tried plotting go.choropleth on it’s own, without using Dash? Just plug the data into go.choropleth and try to plot it using only plotly with map_fig.show(). If that works, then you know the problem is not with plotly or your data, but with the connection between Dash and the graph.

I did try that, and go.choropleth works fine on its own when not using Dash:

It really looks like it’s something to do with the Plotly-Dash connection

I’m having a similar issue where when I run my callback, the go.Choroplethmap can be created on the first run, but is not updated on subsequent callbacks. However I have a go.Densitymap that is successfully updating every callback. Including Fig.show() is creating a figure that changes on each callback.

Do you have updates on how you got this working later?

@Colin_McC-GCS
can you please share a minimal reproducible example so we can run your code locally and reproduce the error you’re getting?

The issue has resolved itself. I cannot replicate it on my original code nor with a modified version. Not sure what, if anything, has changed since then. The only thing I can think of is that clearing my browser’s cache may have fixed it.