load_snapper.Rd
Attach html2canvas and jQuery javascript libraries and download script to the Shiny App environment.
load_snapper( html2canvas = "https://html2canvas.hertzen.com/dist/html2canvas.min.js", jquery = "https://code.jquery.com/jquery-3.5.0.min.js" )
html2canvas | character, url path to html2canvas library. Default: 'https://html2canvas.hertzen.com/dist/html2canvas.js' |
---|---|
jquery | character, url path to jQuery library. Default: 'https://code.jquery.com/jquery-3.5.0.min.js' |
shiny.tag.list
If your app needs to work with clients that won't be able to connect to the wider internet, you'll need to download the javascript files, put it in an app subdirectory (say, html2canvas), and point to the arguments to the their respective paths.
if(interactive()){ options(device.ask.default = FALSE) ui <- fluidPage(id = 'page', # load snapper into the app load_snapper(), titlePanel("Hello Shiny!"), sidebarLayout( sidebarPanel(id = 'side', # add id to side panel sliderInput("obs", "Number of observations:", min = 0, max = 1000, value = 500), # add a download button for the side panel by id snapper::download_button(ui = '#side', label = 'Download Side Panel', filename = 'side_panel.png'), # add a preview button for the side panel by id snapper::preview_button(ui = '#side', previewId = 'preview_side', label = 'Preview Side Panel'), # add a preview button for the main panel by id snapper::preview_button(ui = '#main', previewId = 'preview_main', label = 'Preview Main Panel') ), # Show a plot of the generated distribution mainPanel(id = 'main', # add id to main panel plotOutput("distPlot"), # create a div that will display the content created by preview_side shiny::tags$h3('Preview Side Panel'), snapper::snapper_div(id = 'preview_side'), # create a div that will display the content created by preview_main shiny::tags$h3('Preview Main Panel'), snapper::snapper_div(id = 'preview_main') ) ) ) server <- function(input, output) { output$distPlot <- renderPlot({ hist(rnorm(input$obs)) }) } # Complete app with UI and server components shinyApp(ui, server) }