My idea is to create multiple elements that have radioGroupButtons and plotlyOutput in a module file.
To avoid repetitions I created a function like this bellow:
tabpanel_content <- function(radio_id, plotly_id){
div(
id = "div_1",
style = "",
div(
class = "inputs ",
style = "width: 100%",
radioGroupButtons(
inputId = ns(radio_id),
label = "",
choices = c("Input_1","Input_2"),
status = "success"
)
),
div(style = "",
plotlyOutput(ns("plotly_id"), height = 200,width = "auto"))
)
}
the changes are on radioGroupButtons and plotlyOutput ids.
Then I include this function on the module file:
mod_1_UI <- function(id) {
ns <- NS(id)
tagList(
tabsetPanel(
tabPanel(
strong("TabPanel - Title"),
tabpanel_content(radio_id = 'radio_input_1',plotly_id = 'plotly_chart_1'),
tabpanel_content(radio_id = 'radio_input_2',plotly_id = 'plotly_chart_2'),
tabpanel_content(radio_id = 'radio_input_3',plotly_id = 'plotly_chart_3'),
)))
}
mod_1_Server <- function(id) {
moduleServer(
id,
function(input, output, session) {
}
)
}
And then I include the module on the app file:
library(shiny)
library(shinyWidgets)
source(file = 'module_1.R')
source(file = 'input_functions_1.R')
ui <- fluidPage(
mod_1_UI("mod_1")
)
server <- function(input, output, session) {
}
shinyApp(ui, server)
But I have this error Message: Error in ns(radio_id) : could not find function "ns"
I think the relation between my tabpanel_content function and the module function is the problem. To create something like this, is this the best practice?
Any help?
NS, notns. And here you have to remove the quotes:ns("plotly_id").Error in paste0(inputId, "-label") : cannot coerce type 'closure' to vector of type 'character'