I have a module initiated with golem::add_module(name = "my_module", with_test = TRUE)
.
I have also created a function file with golem::add_fct("my_module", with_test = TRUE)
.
My module is a bit lengthy, but to resume: I have some radioButtons at the top and I want to store input$myRadioButtons in a reactive function.
Inside the server of my_module, I am writing myRadio <- reactive({ return(input$myRadioButtons) })
.
When I call myRadio() below and running the app, I am getting "function myRadio() not found".
I tried swapping the function from a reactive to a normal function myRadio <- function(){ return(input$myRadioButtons) })
but I still get the "function not found" prompt.
Now, I tried moving either the reactive version of myRadio or the normal function version of myRadio to the fct_my_module file, but this time I am prompted with "object 'input' not found".
Writing the function inside the module server does not recognise it, and writting it inside the helper fct_ file (which is outside the server) does not recognise the input.. I am at a loss.
Any help much appreciated, thank you very much in advance!
Edit: Here is what I am doing
#' my_module UI Function
#'
#'
#'
#' @param id,input,output,session Internal parameters for {shiny}.
#'
#' @noRd
#'
#' @importFrom shiny NS tagList
mod_my_module_ui <- function(id){
ns <- NS(id)
tagList(
radioButtons(ns(myRadioButtons), label = 'Pick one', choices = c('a','b','c')),
textOutput(ns(text)),
textOutput(ns(text2))
)
}
#' main Server Functions
#'
#' @noRd
mod_my_module_server <- function(id){
moduleServer( id, function(input, output, session){
ns <- session$ns
# This works
output$text <- renderText(input$myRadioButtons)
# This doesn't work:
myRadio <- reactive({ return(input$myRadioButtons) })
output$text2 <- renderText({ myRadio() })
# This doesn't work either (commenting it out)
# myRadio <- function(){ return(input$myRadioButtons) })
# output$text2 <- renderText({ myRadio() })
})
}
## To be copied in the UI
# mod_my_module_ui("main_1")
## To be copied in the server
# mod_my_module_server("main_1")
Above prompts me with "function 'myRadio()' not found", and when I move it to the external fct___ file the function is found, but the input is not found.