plotly_widget() and as_widget() turn a figure into an htmlwidget,
which is what printing a figure does. Use them to embed figures with
htmltools or htmlwidgets::saveWidget().
Usage
plotly_widget(
fig,
width = NULL,
height = NULL,
elementId = NULL,
config = NULL,
bundle = NULL
)
as_widget(x, ...)Arguments
- fig
A
go_figure(), a figure from apx_*()function, or a list withdata(list of traces),layout,framesandconfigelements.- width, height
Widget size in CSS units, or
NULLfor the layout'swidth/heightor to fill the container.- elementId
Optional element id for the widget.
- config
Plotly.js configuration options (e.g.
list(displayModeBar = FALSE)), merged over those set withconfig().- bundle
The plotly.js bundle to load:
"full","auto"(the smallest bundle with all the figure's trace types) or the name of a partial bundle (seepartial_bundle()). By default, the one set withpartial_bundle(), or theplotly.core.bundleoption ("full"if unset).- x
A figure or htmlwidget.
as_widget()is an S3 generic: the plotly package adds a method for itsplot_ly()objects.- ...
Passed to
plotly_widget().
Details
If the figure's layout has no template, the default template
(see default_template()) is applied.
Numeric arrays in traces are sent to the browser as base64-encoded typed
arrays ({dtype, bdata} objects, as plotly.py does), which are smaller
and faster to load than JSON numbers. JavaScript that reads x.data in
htmlwidgets::onRender() sees these objects rather than arrays; read the
plotted values from el._fullData instead. plotly_json() shows plain
JSON. Vectors of whole numbers are sent as integers; see as_float32()
to send other numbers in single precision. Dates and date-times are sent
as numbers and turned back into "YYYY-MM-DD HH:MM:SS" strings (in the
vector's time zone) in the browser before plotting.