Skip to content
This repository has been archived by the owner on Jun 3, 2024. It is now read-only.

dcc.Graph hoverData not working when graph is embedded inside tabs? #311

Open
chriddyp opened this issue Sep 24, 2018 · 6 comments
Open
Labels
dash-type-bug Something isn't working as intended Status: Triage Needed

Comments

@chriddyp
Copy link
Member

I haven't looked into this yet, but this was reported by the community this week: https://community.plot.ly/t/interactive-graphing-not-working-with-dcc-tab/13852

@valentijnnieman
Copy link
Contributor

Sorry for the delay, but I can confirm that hoverData is not working when a Graph is embedded in Tabs, using the no-callback method. Here's the example from the community forms:

import json
from textwrap import dedent as d
import plotly.graph_objs as go
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output

app = dash.Dash(__name__)

styles = {
    'pre': {
        'border': 'thin lightgrey solid',
    }
}

data=[]

for i in range(3):
    trace = go.Bar(
        y=['a','b','c'],
        x=[2+i,4*i,3-i],
        name='item{}'.format(i),
        orientation = 'h',
        hoverinfo='all',
    )
    data.append(trace)

layout = go.Layout(
        xaxis=dict(
        title='percentage', # adhoc
    ),
    barmode='group',
    autosize=False,
    #width=500,
)

fig = go.Figure(data=data, layout=layout)

app.layout = html.Div([
    dcc.Tabs(id='tabs', children=[
        dcc.Tab(label='chart_1', children=[
            html.Div(className='row', children=[
                dcc.Graph(
                    id='basic-interactions_0',
                    figure=fig
                )
            ]),
        ]),

        dcc.Tab(label='chart_2', children=[
            html.Div(className='row', children=[
                dcc.Graph(
                    id='basic-interactions',
                    figure=fig
                )]),           
            html.Div(className='row', children=[
                html.Div([
                    dcc.Markdown(d("""
                        **Hover Data**
        
                        Mouse over values in the graph.
                    """)),
                    html.Pre(id='hover-data', style=styles['pre'])
                ], className='three columns'),
        
                html.Div([
                    dcc.Markdown(d("""
                        **Click Data**
        
                        Click on points in the graph.
                    """)),
                    html.Pre(id='click-data', style=styles['pre']),
                ], className='three columns'),
        
                html.Div([
                    dcc.Markdown(d("""
                        **Selection Data**
        
                        Choose the lasso or rectangle tool in the graph's menu
                        bar and then select points in the graph.
                    """)),
                    html.Pre(id='selected-data', style=styles['pre']),
                ], className='three columns'),
        
                html.Div([
                    dcc.Markdown(d("""
                        **Zoom and Relayout Data**
        
                        Click and drag on the graph to zoom or click on the zoom
                        buttons in the graph's menu bar.
                        Clicking on legend items will also fire
                        this event.
                    """)),
                    html.Pre(id='relayout-data', style=styles['pre']),
                ], className='three columns')
            ]),
        ])
    ])
])

@app.callback(
    Output('hover-data', 'children'),
    [Input('basic-interactions', 'hoverData')])
def display_hover_data(hoverData):
    print('enter hover callback')
    print(hoverData)
    return json.dumps(hoverData, indent=2)

@app.callback(
    Output('click-data', 'children'),
    [Input('basic-interactions', 'clickData')])
def display_click_data(clickData):
    return json.dumps(clickData, indent=2)

@app.callback(
    Output('selected-data', 'children'),
    [Input('basic-interactions', 'selectedData')])
def display_selected_data(selectedData):
    return json.dumps(selectedData, indent=2)


if __name__ == '__main__':
    app.run_server(debug=True)

@valentijnnieman valentijnnieman added the dash-type-bug Something isn't working as intended label Oct 10, 2018
@valentijnnieman
Copy link
Contributor

I'm hopeful plotly/dash-renderer#101 will resolve this issue too.

@rahul188
Copy link

can anyone please help me with how to add hover data in DCC.graph, please?

@joel314
Copy link

joel314 commented Apr 6, 2021

Hi,

I am using dash_renderer 1.9.0 and it looks like the problem is still there.

Is there any update on this issue? Is there any workaround?

Thanks for your input!

@joel314
Copy link

joel314 commented Apr 7, 2021

I figured out that the issue was caused by this piece of CSS code that I put in the assets folder:

body {
  zoom: 70%;
}

For some reason, it prevented the graphs to be interactive anymore in the tabs.

See: plotly/plotly.js#5288

@ipendlet
Copy link

FWIW the example @valentijnnieman appears to work now.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
dash-type-bug Something isn't working as intended Status: Triage Needed
Projects
None yet
Development

No branches or pull requests

5 participants