buttons: Snapper Buttons

preview_buttonR Documentation

Snapper Buttons

Description

Buttons to populate snapper_div, download to local file, or save to the server the canvas contents.

Usage

preview_button(
  inputId = "btn-Preview-Image",
  label = "Preview",
  ui = "#html-content-holder",
  previewId = "previewImage",
  opts = config()
)

preview_link(
  inputId = "btn-Preview-Image",
  label = "Preview",
  ui = "#html-content-holder",
  previewId = "previewImage",
  opts = config(),
  icon = "camera"
)

download_button(
  inputId = "btn-Convert-Html2Image",
  label = "Download",
  ui = "#html-content-holder",
  filename = "canvas.png",
  opts = config()
)

download_link(
  inputId = "btn-Convert-Html2Image",
  label = "",
  ui = "#html-content-holder",
  filename = "canvas.png",
  opts = config(),
  icon = "camera"
)

save_button(
  inputId = "btn-Save-Html2Image",
  label = "Save",
  ui = "#html-content-holder",
  filename = "canvas.png",
  opts = config(),
  save_dir = getwd()
)

save_link(
  inputId = "btn-Save-Html2Image",
  label = "Save",
  ui = "#html-content-holder",
  filename = "canvas.png",
  opts = config(),
  save_dir = getwd(),
  icon = "camera"
)

Arguments

inputId

character, The input slot that will be used to access the value. Default: 'btn-Preview-Image'

label

character, The contents of the button. Default: 'Preview'

ui

character, The jQuery selector of the target ui element to be captured. Default: '#html-content-holder'

previewId

character, The id that is mapped to the container that captures the canvas output. Default: 'previewImage'

opts

configuration settings to pass to html2canvas.

icon

icon to pass use for in the link objects, Default: 'camera'

filename

character, Local path to save the image. Default: 'canvas.png'

save_dir

directory on the server where the image should be saved, relative to the shiny apps' working directory. If saving the image is successful, input$snap will contain the full path to the image. If not, input$snap will contain an empty string ("").

Details

Use config to define the configuration options

Value

shiny.tag

See Also

actionButton

Other elements: snapper_div()

Examples


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

   # add a preview button for the main panel by id
   snapper::preview_button(ui = '#main',
   previewId = 'preview_main',
   label = 'Preview Main'),

   # add a save button to save the side panel on the server
   snapper::save_button(ui = '#side',
   label = 'Save Side')
 ),

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

}

yonicd/snapper documentation built on Nov. 16, 2023, 5:40 a.m.