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 isFalse
, but if you useTrue
(or equivalently,click_opts()
), the plot will send coordinates to the server whenever it is clicked, and the value will be accessible viainput.xx_click()
, wherexx
is replaced with the ID of this plot. The input value will be a dictionary withx
andy
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 byhover_opts
. The default isFalse
, but if you useTrue
(or equivalently,hover_opts()
), the plot will send coordinates to the server whenever it is clicked, and the value will be accessible viainput.xx_hover()
, wherexx
is replaced with the ID of this plot. The input value will be a dictionary withx
andy
elements indicating the mouse position. To control the hover time or hover delay type, usehover_opts
. brush: bool |
BrushOpts
= False-
Similar to the
click
argument, this can be a boolean or an object created bybrush_opts
. The default isFalse
, but if you useTrue
(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 viainput.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 withxmin
,xmax
,ymin
, andymax
elements indicating the brush area. To control the brush behavior, usebrush_opts
. Multipleoutput_image
/output_plot
calls may share the sameid
value; brushing one image or plot will cause any other brushes with the sameid
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 ofinline
.
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)