Shiny :: Simple example (reactive)

Published by onesixx on

 

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())
        })
    })
})

 

Categories: R-Shiny

onesixx

Blog Owner

Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x