plotly / plotly/dash

Scattermapbox and Choroplethmapbox plots can't be placed under an inactive dcc.Tab

Open
#1,296 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug P3
Dominant language
Python
Stars
24.4k
Forks
2.3k
Avg merge
2d 7h
Merged PRs (30d)
13

Description

I'm building a webapp that has multiple tabs, some of which include Plotly go.Scattermapbox and go.Choroplethmapbox elements. Tab visibilty is controlled by a callback using display set to 'block' or 'none'. I'm getting a Javascript error if I move the Mapbox plots to a tab which is not displayed on app startup.

My current environment (Python 3.6.9 under the Windows Subsystem for Linux version of Ubuntu 18.04 LTS) includes

dash-bootstrap-components (0.9.1)
dash-core-components (1.10.0)
dash-html-components (1.0.3)
dash-renderer (1.4.1)
dash-table (4.7.0)
plotly (4.8.1)

My browser is Chrome 83.0.4103.61.

This is a minimum working example of my code that reproduces the error:

import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output


import pathlib
import configparser


import plotly.express as px
px.set_mapbox_access_token(open(".mapbox_token").read())


df = px.data.carshare()


app = dash.Dash()
app.layout = html.Div([

    dcc.Tabs(
        children=[dcc.Tab(label='Text Tab', value='text'),
                  dcc.Tab(label='Map Tab', value='map')],
        value='text',
        id='tabs'
    ),

    html.Div(id='content-text',
             children=dcc.Markdown("# Some Text")),

    html.Div(
        id='content-map',
        children= [
            dcc.Markdown('# Test of Figure'),
            dcc.Graph(id='test_fig',
                      style={'height': "500px"})
        ]
    )
])


@app.callback([Output('content-text', 'style'),
               Output('content-map', 'style')],
              [Input('tabs', 'value')])
def display_tabs(value):
    tab_settings = [{'display': 'none'}, {'display': 'none'}]
    which_tab = {'text': 0, 'map': 1}
    tab_settings[which_tab[value]] = {'display': 'block'}
    return tab_settings


@app.callback(Output('test_fig', 'figure'),
              [Input('test_fig', 'id')])
def callback_graph(value):

    fig = px.scatter_mapbox(df, lat="centroid_lat", lon="centroid_lon",    
                            color="peak_hour", size="car_hours",
                            color_continuous_scale=px.colors.cyclical.IceFire,
                            size_max=15, zoom=10)

    return fig


app.run_server(debug=True)

When the default value of dcc.Tabs is set to value='map', the app works as expected. When it's set to value='text', the map is not loaded, and the debugger returns the following JS error:

Error: Something went wrong with axis scaling

    at Object.t.setScale (http://127.0.0.1:8050/_dash-component-suites/dash_core_components/async-plotlyjs.v1_10_0m1588696753.js:2:2480138)

    at http://127.0.0.1:8050/_dash-component-suites/dash_core_components/async-plotlyjs.v1_10_0m1588696753.js:2:1985622

    at SVGGElement.<anonymous> (http://127.0.0.1:8050/_dash-component-suites/dash_core_components/async-plotlyjs.v1_10_0m1588696753.js:2:1989968)

    at http://127.0.0.1:8050/_dash-component-suites/dash_core_components/async-plotlyjs.v1_10_0m1588696753.js:2:315738

    at ut (http://127.0.0.1:8050/_dash-component-suites/dash_core_components/async-plotlyjs.v1_10_0m1588696753.js:2:312104)

    at Array.Y.each (http://127.0.0.1:8050/_dash-component-suites/dash_core_components/async-plotlyjs.v1_10_0m1588696753.js:2:315711)

    at draw (http://127.0.0.1:8050/_dash-component-suites/dash_core_components/async-plotlyjs.v1_10_0m1588696753.js:2:1982743)

    at Object.r.drawMarginPushers (http://127.0.0.1:8050/_dash-component-suites/dash_core_components/async-plotlyjs.v1_10_0m1588696753.js:2:2358498)

    at A (http://127.0.0.1:8050/_dash-component-suites/dash_core_components/async-plotlyjs.v1_10_0m1588696753.js:2:2331674)

    at Object.l.syncOrAsync (http://127.0.0.1:8050/_dash-component-suites/dash_core_components/async-plotlyjs.v1_10_0m1588696753.js:2:2247780)

I've had no problems setting display to none for other types of Plotly plots, so figured this has to do with being unable to hide the Mapbox layer?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the minimal example using dcc.Tabs, the display_tabs callback, and dcc.Graph, then reproduce it in the browser with the initial tab set to text. Compare the behavior when the map tab is initially selected and inspect the reported axis-scaling error. Done means Scattermapbox and Choroplethmapbox plots render correctly after being revealed from an initially hidden tab.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, python
Domain
data-visualization, frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.