✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
🐇 Announcing Dash VTK for 3d simulation graphics. Check out the March webinar.

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