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.
outputCodeButton(
outputObj,
label = "Show code",
icon = shiny::icon("code"),
width = NULL,
...
)A shiny output container (e.g., shiny::plotOutput, shiny::textOutput, etc)
The contents of the button or link–usually a text label, but you could also use any other HTML, like an image.
An optional icon() to appear on the button.
The width of the input, e.g. '400px', or '100%';
see validateCssUnit().
Named attributes to be applied to the button or link.
the outputObj wrapped in a card-like HTML container.
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)
}