uiTakeSnapshot: uiTakeSnapshot

Description Usage Arguments Details Value Author(s) Examples

Description

Bulk Grab UI Element Values Given A List Of Names and Input Types

Usage

1
uiTakeSnapshot(inputs, env)

Arguments

inputs

A named list or vector of input types (character), named with the inputId.

env

Environment in which to find the shiny input list.

Details

The output is designed to easily re-create the current state of the UI, setting values with the appropriate update__Input function. Note that it is not possible to set a fileInput value, but it is possible to store the name of the uploaded file.

Value

A list of lists, with variable content according to the following structure:

inputId
type

Input function, as a character string.

value

Value of the UI input at time of function call.

Author(s)

Jon Katz

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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
## Not run: 
# Must be called within a shiny app
library(shiny)
ui <- fluidPage(
    textInput("main", "Plot title:", value="First Plot"),
    numericInput("randn", 'Number of Random Values:', value=10, min=1, step=1),
    column(1, actionButton('submit', 'Submit')),
    column(1, actionButton('reset', 'Previous Settings')),
    div(style='clear:both;',
        column(9, plotOutput('outplot')),
        column(3, htmlOutput('snapshot', container=tags$pre, class='shiny-text-output'))
    )
)

server <- function(input, output, session) {
    snapshot <- list()

    observe({
        input$reset
        if(length(snapshot) > 0) {
            s.el <- length(snapshot)
            if(length(snapshot) > 1) snapshot <- snapshot[(s.el - 1):s.el]
            uiSetSnapshot(snapshot[[1]], session)
        }
        NULL
    })

    output$outplot <- renderPlot({
        input$submit
        isolate({
            input.funs <- c(main='textInput', randn='numericInput')
            snapshot <<- c(snapshot, list(uiTakeSnapshot(input.funs, environment())))
            values <- rnorm(input$randn)
            plot(values, main=input$main)
        })
    })

    output$snapshot <- renderPrint({
        input$submit
        input$reset
        if(length(snapshot)>1) {
            print(snapshot[[length(snapshot)-1]])
        } else print(snapshot[[length(snapshot)]])
    })
}
shinyApp(ui, server)

## End(Not run)

jonkatz2/shinyAddOns documentation built on May 19, 2019, 7:30 p.m.