I'm using a tabsetPanel and and I now want to create a module that adds more than one tab to this panel. Here is my example code:
library(shiny)
library(tidyverse)
resultlistUI <- function(id) {
ns <- NS(id)
tabPanel(
title = "Result1",
"Some text here 2"
)
tabPanel(
title = "Result2",
"Some text here 3"
)
}
resultlist <- function(input, output, session) {
}
ui <- fluidPage(
tabsetPanel(
id = "tabs",
tabPanel(
title = "Tab 1",
"Some text here"
),
resultlistUI(id = "resultlist1")
)
)
server <- function(input, output, session) {
}
shinyApp(ui = ui, server = server)
I was first wondering why I could not simply separate the two tabs with a comma. When I execute the code only my second tab "Result2" is added to the tabsetPanel. I also tried to use tagList but then none of the tabs was shown. What am I doing wrong?
EDIT: Complete minimal reproducible example added - only first tab from main app and the second tab from the module are displayed.
Probably the issue come from the way the function tabsetPanel consumes its arguments. The function wants tabPanels separated per commas.
While doing what you are doing you provide two tabPanels within one argument.
So you have got to come up with something that allows you to provide one tab per argument. By returning a list from your module and using the function do.call you can achieve this.
library(shiny)
library(tidyverse)
resultlistUI <- function(id) {
ns <- NS(id)
list(
tabPanel(
title = "Result1",
"Some text here 2"
),
tabPanel(
title = "Result2",
"Some text here 3"
))
}
resultlist <- function(input, output, session) {
}
ui <- fluidPage(
do.call(tabsetPanel,
list(id = 'tabs',
tabPanel(
title = "Tab 1",
"Some text here"
)) %>% append(resultlistUI(id = "resultlist1")))
)
server <- function(input, output, session) {
}
shinyApp(ui = ui, server = server)