ui.output_plot

ui.output_plot(id, width='100%', height='400px', *, inline=False, click=False, dblclick=False, hover=False, brush=False, fill=MISSING)

Create a output container for a static plot.

Place a plot result in the user interface. See plot for more details on what types of plots are supported.

Parameters

id: str

An output id.

width: str | float | int = ‘100%’

The CSS width, e.g. ‘400px’, or ‘100%’.

height: str | float | int = ‘400px’

The CSS height, e.g. ‘100%’ or ‘600px’.

inline: bool = False

If True, the result is displayed inline.

click: bool | ClickOpts = False

This can be a boolean or an object created by click_opts. The default is False, but if you use True (or equivalently, click_opts()), the plot will send coordinates to the server whenever it is clicked, and the value will be accessible via input.xx_click(), where xx is replaced with the ID of this plot. The input value will be a dictionary with x and y elements indicating the mouse position.

dblclick: bool | DblClickOpts = False

This is just like the click parameter, but for double-click events.

hover: bool | HoverOpts = False

Similar to the click argument, this can be a boolean or an object created by hover_opts. The default is False, but if you use True (or equivalently, hover_opts()), the plot will send coordinates to the server whenever it is clicked, and the value will be accessible via input.xx_hover(), where xx is replaced with the ID of this plot. The input value will be a dictionary with x and y elements indicating the mouse position. To control the hover time or hover delay type, use hover_opts.

brush: bool | BrushOpts = False

Similar to the click argument, this can be a boolean or an object created by brush_opts. The default is False, but if you use True (or equivalently, brush_opts()), the plot will allow the user to “brush” in the plotting area, and will send information about the brushed area to the server, and the value will be accessible via input.plot_brush(). Brushing means that the user will be able to draw a rectangle in the plotting area and drag it around. The value will be a named list with xmin, xmax, ymin, and ymax elements indicating the brush area. To control the brush behavior, use brush_opts. Multiple output_image/output_plot calls may share the same id value; brushing one image or plot will cause any other brushes with the same id to disappear.

fill: bool | MISSING_TYPE = MISSING

Whether or not to allow the plot output to grow/shrink to fit a fillable container with an opinionated height (e.g., page_fillable). If no fill value is provided, it will default to the inverse of inline.

Returns

Type Description
Tag A UI element

See Also

Examples

#| standalone: true
#| components: [editor, viewer]
#| layout: vertical
#| viewerHeight: 400

## file: app.py
import matplotlib.pyplot as plt
import numpy as np

from shiny import App, Inputs, Outputs, Session, render, ui

app_ui = ui.page_fluid(
    ui.input_slider(
        "n", "input_slider()", min=10, max=100, value=50, step=5, animate=True
    ),
    ui.output_plot("p"),
)


def server(input: Inputs, output: Outputs, session: Session):
    @render.plot
    def p():
        np.random.seed(19680801)
        x_rand = 100 + 15 * np.random.randn(437)
        fig, ax = plt.subplots()
        ax.hist(x_rand, int(input.n()), density=True)
        return fig


app = App(app_ui, server)