Shiny modules: multiple outputs from one module

Hi.
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)
	
	tagList(
		uiOutput(ns("output1")),
		htmlOutput(ns("output2"))
	)
}

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)
	return(rlist)

	
}
2 Likes

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.