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

How to specify plotly's config attribute? #173

Open
DvGils opened this issue Dec 19, 2024 · 5 comments
Open

How to specify plotly's config attribute? #173

DvGils opened this issue Dec 19, 2024 · 5 comments

Comments

@DvGils
Copy link

DvGils commented Dec 19, 2024

Hi!

Currently, It is impossible to change any configuration options (e.g., adding or removing buttons from the modebar) when rendering a Plotly Figure using shinywidgets. Any chance this can be supported?

@cpsievert
Copy link
Collaborator

Unfortunately this is a limitation of the underlying plotly FigureWidget, so an official fix would have to come them plotly/plotly.py#1074

That said, there are CSS workarounds you can do to hide stuff from the modebar. I've done this a few times to hide the modebar completely. If you're curious how to do that, I can get a minimal example for you.

@DvGils
Copy link
Author

DvGils commented Jan 24, 2025

Thank you for your response @cpsievert

I have tried hiding stuff using CSS myself, but couldn't get it to work. A small example would be very helpful!

@cpsievert
Copy link
Collaborator

Actually, with the latest releases of plotly and shinywidgets, you can now specify a _config on a FigureWidget() object.

Still not totally ideal (maybe @render_plotly() could handle this via a config argument?), but at least this works for now:

import plotly.express as px
import plotly.graph_objects as go
import shiny.express

from shinywidgets import render_plotly

@render_plotly
def plot():
    fig = px.histogram(
        px.data.tips(),
        x="total_bill",
    )

    w = go.FigureWidget(fig)
    w._config["displayModeBar"] = False
    return w

@cpsievert cpsievert changed the title Add config attribute when rendering Plotly How to specify plotly's config attribute? Jan 29, 2025
@DvGils
Copy link
Author

DvGils commented Jan 30, 2025

Thanks!

Not sure why but your implementation does not work for me using shiny core.

This works for me:
w._config = fig._config | {"showModeBar": False}

@cpsievert
Copy link
Collaborator

cpsievert commented Jan 30, 2025

Can you provide a complete example and double-check you have shinywidgets>=0.5 and plotly>=6.0?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants