I would like to define a function that calls shiny functions with reactive input as arguments. For this example:
library(shiny)
ui <- fluidPage(
actionButton("do", "Click Me")
)
server <- function(input, output, session) {
clickFunction<-function(x){
observeEvent(x, {print("got it")})
}
clickFunction(x = input$do)
}
shinyApp(ui, server)
I expect
[1] "got it"
when I klick the button "Click Me", but instead there is no output.
How can let observeEvent observe the reactive inputs?
I think it might depend on the enviroment arguments of observeEvent, but I am inexperienced in using them.
Thank you in andvance.
observeEvent()
is called from insideserver
. Your example doesn't work asclickFunction()
is not called (it's not in a reactive environment). The usual way to callobserveEvent()
would beserver <- function(input, output, session) {observeEvent(input$do,{print("got it")})}
- Michael Bird