Description Usage Arguments Value Author(s) Examples
Bulk Set UI Element Values Given A Named List Of Input Types And Values
1 | uiSetSnapshot(snapshot, sess)
|
snapshot |
A Named List Of Input Types And Values. |
sess |
The shiny |
Returns a list of update results.
Jon Katz
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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.