How to return reactive expression in Shiny module

743 views
Skip to first unread message

Samuel Bohman

unread,
Dec 21, 2016, 2:52:06 AM12/21/16
to Shiny - Web Framework for R
If I have a module that needs to return a list of reactive expressions from the module server function, is this the correct syntax?

return(list(exp_1, exp_2, exp_3))

And a follow up question is how do you use such a list of multiple reactive expressions in the server function of the Shiny app? Garrett Grolemund explains in this video tutorial that you should save the callModule() data in a variable, and then "crack" open that variable with ()' when you are going to use it. But what do you do if you have a list of several reactive expressions that contain return values for different purposes in the main app?

Thanks in advance.

Joe Cheng

unread,
Dec 21, 2016, 10:42:52 AM12/21/16
to Samuel Bohman, Shiny - Web Framework for R
That's correct. And if the module that returns that is called "foo" then you'd use it like this:

fooResult <- callModule(foo, "id")
fooResult$exp_1()

(You'd have to do that second line in a reactive expression or observer but hopefully you get the idea...?)
--
You received this message because you are subscribed to the Google Groups "Shiny - Web Framework for R" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/shiny-discuss/3ce18d4d-fbbb-4723-a556-d2e8bf6bc50f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Samuel Bohman

unread,
Dec 21, 2016, 11:12:47 AM12/21/16
to Shiny - Web Framework for R, samuel...@gmail.com
Thanks Joe. My app is running without any warnings or error messages in the Console. However, I am still not getting the results I am trying to achieve. I am using the reactive expressions in an observer, like so: https://gist.github.com/samuel-bohman/959e17e70eedb0bae527771ee7c0719a

Joe Cheng

unread,
Dec 21, 2016, 11:15:41 AM12/21/16
to Samuel Bohman, Shiny - Web Framework for R
That should work. Try calling str() on some of those results and make sure you're seeing the values you're expecting?

Samuel Bohman

unread,
Dec 21, 2016, 12:25:15 PM12/21/16
to Shiny - Web Framework for R, samuel...@gmail.com
How and when do I do that while the app is running? I'm sorry, I'm a beginner in Shiny!

Samuel Bohman

unread,
Dec 21, 2016, 1:19:19 PM12/21/16
to Shiny - Web Framework for R, samuel...@gmail.com
Here is the link: https://xplor.shinyapps.io/xplor/ My current hypothesis is that input$alt is empty because it is rendered through a renderUI in the module server. This causes the app not to work because of the null_check() function in server.R. I'm planning to eliminate the null check functions and use req() instead, but it has not worked out for me so far. Thanks again Joe, you are very helpful and I appreciate your help a lot!
Reply all
Reply to author
Forward
0 new messages