Learn R Programming

htmlwidgets (version 1.6.4)

htmlwidgets-shiny: Shiny bindings for HTML widgets

Description

Helpers to create output and render functions for using HTML widgets within Shiny applications and interactive Rmd documents.

Usage

shinyWidgetOutput(
  outputId,
  name,
  width,
  height,
  package = name,
  inline = FALSE,
  reportSize = TRUE,
  reportTheme = FALSE,
  fill = !inline
)

shinyRenderWidget(expr, outputFunction, env, quoted, cacheHint = "auto")

Value

An output or render function that enables the use of the widget within Shiny applications.

Arguments

outputId

output variable to read from

name

Name of widget to create output binding for

width, height

Must be a valid CSS unit (like "100%", "400px", "auto") or a number, which will be coerced to a string and have "px" appended.

package

Package containing widget (defaults to name)

inline

use an inline (span()) or block container (div()) for the output

reportSize

Should the widget's container size be reported in the shiny session's client data?

reportTheme

Should the widget's container styles (e.g., colors and fonts) be reported in the shiny session's client data?

fill

whether or not the returned tag should be treated as a fill item, meaning that its height is allowed to grow/shrink to fit a fill container with an opinionated height (see htmltools::bindFillRole() for more). Examples of fill containers include bslib::card() and bslib::card_body_fill().

expr

An expression that generates an HTML widget (or a promise of an HTML widget).

outputFunction

Shiny output function corresponding to this render function.

env

The environment in which to evaluate expr.

quoted

Is expr a quoted expression (with quote())? This is useful if you want to save an expression in a variable.

cacheHint

Extra information to use for optional caching using shiny::bindCache().

Details

These functions are delegated to from within your widgets own shiny output and render functions. The delegation is boilerplate and always works the same for all widgets (see example below).

Examples

Run this code
# shiny output binding for a widget named 'foo'
fooOutput <- function(outputId, width = "100%", height = "400px") {
  htmlwidgets::shinyWidgetOutput(outputId, "foo", width, height)
}

# shiny render function for a widget named 'foo'
renderFoo <- function(expr, env = parent.frame(), quoted = FALSE) {
  if (!quoted) { expr <- substitute(expr) } # force quoted
  htmlwidgets::shinyRenderWidget(expr, fooOutput, env, quoted = TRUE)
}

Run the code above in your browser using DataLab