Can we use output$x as input in server using shiny?

Hi,

I have made some calculations and computed my output in the server. Can I use the Output as input again?

Code:

          output$Myfueleffwithoutload <- renderText({

          paste("Fuel efficiency without load of the vehicle will be Km/Ltr", input$fuel_eff_with_load + 0.5)
          
        })

Can i make use of output$Myfueleffwithoutload as input for other calculation in the server side while making dashboard in shiny

My (limited) understanding is that renderXXX functions are used to create html elements for the ui.

You can create other kinds of reactive objects for use in the server using reactive, reactiveValue and reactiveVals for example.

If you want to modify something in the ui based on calculations in the server you can use updateXXX to update one of the widgets.

For more complex widgets such as plotly plots or DT datatables you can use proxyXXX.

Hope this helps.

1 Like

My suggestion would be to store that return value in a reactiveValue where it gets defined whenever your input value is changed. Then use that reactiveValue anywhere you want. Something like this:

reac_val <- reactiveValue(data = NULL)

observeEvent(input$fuel_eff_with_load, {
  reac_val$data <- input$fuel_eff_with_load + 0.5
})

output$Myfueleffwithoutload <- renderText({

          paste("Fuel efficiency without load of the vehicle will be Km/Ltr", reac_val$data)
          
        })
2 Likes

Thank you sir for your inputs. This helps.

Thank you sir. Your inputs were helpful.

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