0

I am pretty new to Shiny and dealing with the following problem, upon pressing an actionButton in shiny, I want it to do multiple calculations. I use the handler of observeEvent.

An example:

library(shiny)
ui <- fluidPage(
  sidebarLayout(
  sidebarPanel(`

     actionButton("calc","calculate stuff")),
  mainPanel(
     textOutput("result")
 )
)
)


server <- function(input,output){
  observeEvent(input$calc, {output$result <- renderText({"only this is not enough"})  })
}


shinyApp(ui,server')`

Now what I would want is where the output$result is made in the server-observeEvent, I would like to perform additional tasks, say assign a variable a <- 12, calculate B4 <- input$ID1*inputID2 etc.

This can not be hard I imagine.. but I am just not getting there.

kind regards,

Pieter

Piet93
  • 169
  • 1
  • 13

1 Answers1

0

You can use isolate, see this example:

library(shiny) 
ui <- fluidPage(
  sidebarLayout(
    sidebarPanel( 
      numericInput(inputId = 'x', label = 'Select a value for x', value = 1),
      actionButton(  "calc", "calculate stuff" )  
    ),
    mainPanel(
      textOutput("result")
    )
  )
) 

server <- function(input, output) {   
  output$result <- renderText({
    input$calc 
    isolate({
      y<- input$x *2 
      paste("The result is:", y) 
    }) 
  }) 
}  
shinyApp(ui, server)
Eduardo Bergel
  • 2,685
  • 1
  • 16
  • 21
  • Thank you @(Ron Talbot). I found that with for instance observe() one can also easily perform more tasks. Do you know what is more efficient programming / better suitable? – Piet93 Sep 23 '16 at 14:39