register_output: Register output and output options

View source: R/shiny-outputs.R

register_outputR Documentation

Register output and output options

Description

Enable advanced output gadgets such as expanding the output in another browser window, or downloading the rendered data.

Usage

register_output_options(
  outputId,
  ...,
  .opt = list(),
  extras = list(),
  session = shiny::getDefaultReactiveDomain()
)

get_output_options(outputId, session = shiny::getDefaultReactiveDomain())

register_output(
  render_function,
  outputId,
  export_type = c("none", "custom", "pdf", "csv", "3dviewer", "htmlwidget"),
  export_settings = list(),
  quoted = FALSE,
  output_opts = list(),
  session = shiny::getDefaultReactiveDomain()
)

get_output(outputId, session = shiny::getDefaultReactiveDomain())

Arguments

outputId

output ID in the scope of current shiny session

..., output_opts, .opt

output options

extras

extra information to store

session

shiny session instance

render_function

shiny render function

export_type

type of export file formats supported, options are 'none' (do not export), 'custom', 'pdf' (for figures), 'csv' (for tables), '3dviewer' (for 'RAVE' 3D viewers), 'htmlwidget' (for 'HTML' widgets).

export_settings

a list of settings, depending on export type; see 'Details'.

quoted

whether render_function is quoted; default is false

Details

Default shiny output does not provide handlers for downloading the figures or data, and is often limited to the 'HTML' layouts. 'RAVE' dashboard provides such mechanisms automatically with few extra configurations.

Value

Registered output or output options.

Examples



if(interactive()) {

library(shiny)
library(ravedash)

rave_id <- paste(sample(c(letters, LETTERS, 0:9), 20, replace = TRUE),
                 collapse = "")

ui <- function(req) {
  query_string <- req$QUERY_STRING
  if(length(query_string) != 1) {
    query_string <- "/"
  }
  query_result <- httr::parse_url(query_string)

  if(!identical(toupper(query_result$query$standalone), "TRUE")) {
    # normal page
    basicPage(
      output_gadget_container(
        plotOutput("plot", brush = shiny::brushOpts("plot__brush")),
      )
    )
  } else {
    # standalone viewer
    uiOutput("viewer")
  }
}

server <- function(input, output, session) {

  bindEvent(
    safe_observe({
      query_string <- session$clientData$url_search
      query_result <- httr::parse_url(query_string)

      if(!identical(toupper(query_result$query$module), "standalone_viewer")) {
        # normal page
        register_rave_session(session = session, .rave_id = rave_id)
        register_output(
          renderPlot({
            plot(1:100, pch = 16)
          }),
          outputId = "plot", export_type = "pdf",
          output_opts = list(brush = shiny::brushOpts("plot__brush"))
        )
        output$plot <- renderPlot({
          input$btn
          plot(rnorm(100), pch = 16)
        })
      } else {
        # standalone viewer
        standalone_viewer(outputId = "plot", rave_id = rave_id)
      }
    }),
    session$clientData$url_search
  )


}

shinyApp(ui, server, options = list(port = 8989))
}


ravedash documentation built on Oct. 16, 2022, 1:06 a.m.