Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix plotly eventdata undefined val #4355

Merged
merged 2 commits into from
Jan 29, 2023
Merged

Conversation

MarcSkovMadsen
Copy link
Collaborator

@MarcSkovMadsen MarcSkovMadsen commented Jan 29, 2023

Fixes #4354

Root Cause

After logging values in the assignments below I could see that for example this.model.click_data was assigned a value that contained the key text with a value of undefined. This caused the error Uncaught Error: [object Undefined] is not serializable.

image

Solution

The solution is to adding further clean up to filterEventData.

The solution works

plotly-donut-works.mp4
import pandas as pd
import param as pm
import panel as pn
import plotly.express as px

df = pd.DataFrame({"ticker": ["A", "B", "C"], "value": [1, 2, 3]})


def portfolio_distribution(_=None, data=df):
    """Returns the distribution of the portfolio"""
    portfolio_total = data["value"].sum()

    fig = px.pie(
        data,
        values="value",
        names="ticker",
        hole=0.3,
        title=f"Portfolio Total ${portfolio_total:,.0f}",       
    )
    fig.layout.autosize = True
    return fig


plot = pn.pane.Plotly(
    portfolio_distribution(),
    config={"responsive": True},
    sizing_mode="stretch_both",
)

pn.Column(
    plot.param.hover_data,
    plot.param.click_data,
    plot,
    height=800,
    sizing_mode="stretch_width",
).servable()

panel/models/plotly.ts Outdated Show resolved Hide resolved
@philippjfr philippjfr merged commit 4847a39 into main Jan 29, 2023
@philippjfr philippjfr deleted the fix/plotly-eventdata-undefined branch January 29, 2023 11:34
philippjfr pushed a commit that referenced this pull request Jan 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Click and Hover data not working for Plotly pie chart: not serializable
2 participants