Beginner to R and shiny here! Tried to make a minimal working example... I want to check a condition on a reactive input value. What am I doing wrong?
library(shiny)
ui<-fluidPage(
numericInput(inputId="a", label=NULL, value=0),
textOutput(outputId="out")
)
server <- function(input, output) {
x <- reactive(input$a)
if (x() < 4)
{y<-1}
else
{y<-0}
output$out <- renderText({y})
}
shinyApp(ui = ui, server = server)
The error message:
Operation not allowed without an active reactive context. (You tried to do something that can only be done from inside a reactive expression or observer.)
x()within a reactive context (for example, insideobserve,local,render....functions). Also youyvalue must be defined outside thefunctionand in the same level or upper level of where it is used.renderTextinput$ais already reactive by itself so you don't need to enclose it withreactiveand assign to a new variable.