I need to get multiple outputs from reactive component in shiny. Example:
output_a,output_b <- reactive({
a <- input$abc
b <- input$abc*10
a
b
})
How could something like above be done through which I can get two outputs a and b from one reactive component?
So I had the same issue, I wanted two outputs from one reactive (I was using a for loop and an ifelse statement to assign variables to 1 of 2 lists, and I needed both lists to be returned).
I found the following workaround, I'm not sure if it will also work for you, but I'm posting it here in case it helps someone:
combo_output <- reactive({
a <- input$abc
b <- input$abc*10
combo <- list(a = a, b = b)
combo
})
then you can access these later as such:
output$someOutput <- renderSomething({
combo <- combo_output()
a <- combo$a
b <- combo$b
...
})
Not sure if this is an optimal solution, but it worked for me.
If I understand correctly you would like to create a reactive to changes in input$abc. Every time the UI would change the input$abc, you would like the values of the server for a and b to change.
If so: Based on the tutorial, I would suggest having 2 successive reactives:
output_a<-reactive({
input$abc
})
output_b<-reactive({
input$abc*10
})
Keep in mind that they will be successively executed, first you will get output_a and afterwards output_b.
Hope this helped you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With