Skip to content

[Bug]: plotly plots jump (becomes smaller then larger) when re-rendered #1917

Open
@injo11

Description

@injo11

Component

UI (ui.*)

Severity

P3 - Low (minor inconvenience)

Shiny Version

1.3.0

Python Version

3.12.3

Minimal Reproducible Example

from shiny.express import render, ui, input
from shinywidgets import render_plotly
import plotly.graph_objects as go
import matplotlib.pyplot as plt
import numpy as np

ui.input_numeric("amplitude", "amplitude", value=1)

with ui.card():
    @render_plotly
    def plot_plotly():
        x = np.linspace(0, 10, 100)
        y = input.amplitude()*np.sin(x)
        fig = go.Figure()
        fig.add_scatter(x=x, y=y, mode='lines')
        
        return fig
    
    @render.plot
    def plot_matplotlib():
        x = np.linspace(0, 10, 100)
        y = input.amplitude()*np.sin(x)
        fig = plt.figure()
        plt.plot(x,y)
        return fig

Behavior

When the amplitude input is changed, the matplotlib graph stays the same size, but the plotly graph becomes smaller, and then larger, so "jumping".

Error Messages (if any)

Environment

OS: Ubuntu 24.04
Browser: Chrome version 131.0.6778.264 
Dependencies: numpy

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions