eventReactive example

Published onesixx on

 

https://shiny.rstudio.com/images/shiny-cheatsheet.pdf

library(shiny)
ui <- fluidPage(
  textInput("x","input Text:",""),
  actionButton("go", "Proceed"),
  textOutput("result")
)
server <-
  function(input,output){ 
    re <- eventReactive(input$go, {
      input$x
    })
    output$result <- renderText({ re()  })
  }

shinyApp(ui, server)

 

library(shiny)
ui <- fluidPage(
  column(4,
    numericInput("x", "Value", 5), br(),
    actionButton("button", "Show")
  ),
  column(8, tableOutput("table"))
)
server <-
  function(input,output){ 
    # Take a reactive dependency on input$button, but
    # not on any of the stuff inside the function
    df <- eventReactive(input$button, {
      cars %>% head(input$x)
    })
    output$table <- renderTable({
      df()
    })
    
    # Additional :  Take an action every time button is pressed;
    # here, we just print a message to the console
    observeEvent(input$button, {
      cat("Showing", input$x, "rows\n")
    })
    
  }
shinyApp(ui, server)

 

 

Categories: Shiny

onesixx

Blog Owner

Leave a Reply

Your email address will not be published.