[Python] Configure plotly in shiny for Python

Discussão em 'Python' iniciado por Stack, Setembro 16, 2024.

  1. Stack

    Stack Membro Participativo

    How do I configure a plotly graph in shiny for Python?

    Consider the following minimal shiny example.

    from shiny import ui, App
    from shinywidgets import output_widget, render_widget
    import plotly.express as px
    import plotly.graph_objects as go

    app_ui = ui.page_fluid(
    output_widget("plotly")
    )

    def server(input, output, session):
    @render_widget
    def plotly():
    df = px.data.gapminder().query("country=='Canada'")
    fig = px.line(df, x="year", y="lifeExp", title='Life expectancy in Canada')
    return go.FigureWidget(fig)

    app = App(app_ui, server)


    How do I set the config = {'displayModeBar': False}.

    I cannot use fig.show(config=config) as this opens a seperate tab with just the plotly graph.

    @render_widget and go.FigureWidget() also do not seem to be able to accept the option.

    All online resources point to using fig.show(), which I cannot use in shiny for Python. Using fig.show(config=config) opens a seperate tab with just the plotly graph. I have searched the internet, but I have not come yet to a workaround.

    In R, I can just add the config to the fig object.

    Why is this not the case in Python?

    Continue reading...

Compartilhe esta Página