Reactive wrapper error

Quite ironically, while preparing a reprex, I ran into following error, which I see no reason to occur, hence posting here. I've seen other similar errors, but not able to understand what is going wrong here. The error is:

Warning: Error in : Operation not allowed without an active reactive context. * You tried to do something that can only be done from inside a reactive consumer. 58: Error : Operation not allowed without an active reactive context. * You tried to do something that can only be done from inside a reactive consumer.

library(shiny)

ui <- fluidPage(
    sliderInput("x","X",min = 1,max = 100,value = 5),
    sliderInput("y","Y",min = 1,max = 100,value = 5),
    sliderInput("z","Z",min = 1,max = 100,value = 5),

    plotOutput("class_plot")
)


server <- function(input, output, session){

    
   observe(req(input$x),{
     x <- reactive(input$x)
     y <- reactive(input$y)
     z <- reactive(input$z)
     
     
     result <- reactive(eval(parse(text = "36+x()*6+y()*3+z()*2")))
     first <- reactiveVal(NULL)
     second <- reactiveVal(NULL)
     
     if(result()<= 100){first("red")}
     else if(result() >100 & result() <= 200){first("blue")}
     else if(result() >200 & result() <= 300){first("green")}
     else if(result() >300 & result() <= 400){first("yellow")}
     else if(result() >400 & result() <= 500){first("orange")}
     else {first("No_way")}
     
     if(result()<= 200){second("easy")}
     else if(result() > 200 & result() <= 400){second("medium")}
     else {second("Difficult")}
     
     output$class_plot <- renderPlot({
       NULL
     })
   })
}


shinyApp(ui, server)

Thanks in advance.

your wrote observe(
but you passed parameters as if you intended observeEvent(

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.