Description Usage Arguments Value Examples
uses javascript libraries, PrismJS and ClipboardJS to highlight
code and handle copying of code to clipboard respectively. Dependencies
must be loaded in the module header. Helper functions
prismDependencies
and clipboardjsDependencies
included to streamline loading from content distribution network.
1 2 3 | show_code_modal(server, ..., title = "R Code", id = "modal_clipboardjs_btn",
envir = parent.frame(), code = get_code(server, ..., call_outputs = TRUE,
envir = envir))
|
server |
The server function handle for construction of code |
... |
Any outputs for which code should be constructed. If none are passed, all code is produced. |
title |
Title of the code modal |
id |
css id of the code modal |
envir |
environment for collecting code artifacts |
code |
code used to generate output can be passed directly as an alternative to the server, ellipses and envir arguments |
a shiny modalDialog with copy to clipboard button and code necessary to generate outputs in server function
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | ## Not run:
library(shiny)
ui <- fluidPage(
scriptglossJS(),
selectInput('x', 'x axis', choices = names(mtcars)),
selectInput('y', 'y axis', choices = names(mtcars)),
actionButton("show_code", "Show R Code", icon("code")),
plotOutput('plot')
)
srv <- function(input, output, session) {
internal_data <- mtcars
output$plot <- renderPlot({
plot(
x = internal_data[[input$x]],
y = internal_data[[input$y]],
xlab = input$x,
ylab = input$y)
})
observeEvent(input$show_code, show_code_modal(srv, 'plot'))
}
shinyApp(ui, srv)
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.