show_code_modal: Display independent code in modal dialog

Description Usage Arguments Value Examples

Description

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.

Usage

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))

Arguments

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

Value

a shiny modalDialog with copy to clipboard button and code necessary to generate outputs in server function

Examples

 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)

dgkf/scriptgloss documentation built on June 8, 2019, 8:43 p.m.