outputCodeButton {shinymeta}R Documentation

Overlay an icon on a shiny output

Description

Intended for overlaying a button over a shiny output, that when clicked, displays code for reproducing that output. The button is similar to an shiny::actionButton(), but instead of providing an inputId, the id is determined by the id of the outputObj. The name of that input is a function of outputObj's outputId: input$OUTPUTID_output_code.

Usage

outputCodeButton(
  outputObj,
  label = "Show code",
  icon = shiny::icon("code"),
  width = NULL,
  ...
)

Arguments

outputObj

A shiny output container (e.g., shiny::plotOutput, shiny::textOutput, etc)

label

The contents of the button or link–usually a text label, but you could also use any other HTML, like an image.

icon

An optional icon() to appear on the button.

width

The width of the input, e.g. '400px', or '100%'; see validateCssUnit().

...

Named attributes to be applied to the button or link.

Value

the outputObj wrapped in a card-like HTML container.

See Also

displayCodeModal

Examples


if (interactive()) {
  library(shiny)
  ui <- fluidPage(
    sliderInput("n", label = "Number of samples", min = 10, max = 100, value = 30),
    outputCodeButton(plotOutput("p"))
  )
  server <- function(input, output) {
    output$p <- metaRender(renderPlot, {
      plot(sample(..(input$n)))
    })
    observeEvent(input$p_output_code, {
      code <- expandChain(output$p())
      displayCodeModal(code)
    })
  }
  shinyApp(ui, server)
}


[Package shinymeta version 0.2.0.3 Index]