2
votes

I am building a shinyApp, but there is something I do not understand clearly since the beginning of my work. I'm wondering how can we use inputs variables in the server function without put them in a renderSomething...

For example, here it is a short part of my code in the server function :

server <- function(input,output){

output$text <- renderText({"My text"})

updating <- reactive( {if (input$nbenfants==0){
 updateNumericInput(session,"n2",value=0)
 updateNumericInput(session,"n3",value=0)
 updateNumericInput(session,"n4",value=0)
 updateNumericInput(session,"n5",value=0)
 updateNumericInput(session,"n6",value=0)
 updateNumericInput(session,"n7",value=0)
 updateNumericInput(session,"n8",value=0)
}})

I would like to update some parameters if the condition input$nbenfants==0 is true. But I can't figure out how to "stock" the result ? When I try to call the function after (updating()), R returns an error :

Error in .getReactiveEnvironment()$currentContext() : 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.) ERROR: [on_request_read] connection reset by peer ERROR: [on_request_read] connection reset by peer

1

1 Answers

0
votes

I think you should use observeEvent to act when the input$nbenfant value changes:

server <- function(input,output){

output$text <- renderText({"My text"})

observeEvent(input$nbenfant,{
if(input$nbenfant ==0) {
updateNumericInput(session,"n2",value=0)
updateNumericInput(session,"n3",value=0)
updateNumericInput(session,"n4",value=0)
updateNumericInput(session,"n5",value=0)
updateNumericInput(session,"n6",value=0)
updateNumericInput(session,"n7",value=0)
updateNumericInput(session,"n8",value=0)
}})

Hope that will work

Gottavianoni