Shiny modules: multiple outputs from one module

What is the proper design pattern for shiny modules with multiple outputs? So far, I went with 1 module = 1 output strategy. But it seems kinda wasteful to duplicate collecting from sql db when the second output is a derivative of the first one (dataset grouped and summarized on a higher level). Another option would be to create second module which takes the output of the first one and creates the derivative. This on the other hand (somewhat unnecesarily?) increases number of modules in app.

What would be the correct (intended by shiny developers) strategy here?
Thank you!

You can easily make a module return any number of reactive objects in a list by doing something like this (this is an example skeleton structure with some outputs sprinkled in):

exampleModuleUI <- function(id) {
	ns <- NS(id)

exampleModule <- function(input, output, session) {
	ns <- session$ns
	output$output1 <- renderUI({ 
	output$output2 <- renderText({

	r1 <- reactive({
	r2 <- reactive({
	# Return a list of reactive objects
	rlist <- list(r1 = r1, r2 = r2)

1 Like

Thanks Valeri, this looks like the best option!

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