Shiny :: Simple example (reactive)
library(shiny) ui <- fluidPage( sliderInput(inputId = "num", label = "Choose a number", min = 1, max = 100, value = 25) ,actionButton(inputId = "go", label = "Print Value") ,plotOutput("hist") ) server <- function(input, output, session){ data <- eventReactive(input$go, { rnorm(input$num) }) observeEvent(input$go, { output$hist <- renderPlot({ hist(data()) }) }) } shinyApp(ui,server)
UI
library(shiny) # setwd("/Users/onesixx/Dropbox/Rhome/shiny/simple") shinyUI( fluidPage( sliderInput(inputId = "num", label = "Choose a number", min = 1, max = 100, value = 25) ,actionButton(inputId = "go", label = "Print Value") ,plotOutput("hist") ))
Server
library(shiny) shinyServer ( function(input, output, session){ data <- eventReactive(input$go, { rnorm(input$num) }) observeEvent(input$go, { output$hist <- renderPlot({ hist(data()) }) }) })