print the content of returned reactive expression from module

Hi there,
I'm new to Shiny and still try to wrap my head around modules and how to return reactive expressions from there. I would like to be able to follow the changes of a reactive expression based on user input. Therefore, I would like to use a simple print function to output the content of a given expression to the console, but I fail to do so. I found a way to do it with reactive values but this doesn't work for reactive expressions. If I simply try to use print(ret()$mut) in the main app I get following error:
Error in ret() : could not find function "ret"
Here is a minimal example:

library(shiny)

##### Module UI function #####
cellLineSelectorUI <- function(id){
  # create a namespace function using the provided id
  ns <- NS(id)
  
  tagList(
    mainPanel(
      titlePanel("Interactive Cell line selector"),
      tabsetPanel(
        tabPanel("Simple Selection / Gene expression based",
                 sidebarLayout(
                   sidebarPanel(radioButtons(inputId = ns("project"), #name of input
                                             label = "Project:", #label displayed in ui
                                             choices = as.character(c("abc", "cdf")),
                                             selected = "abc") #default choice (not required)
                   ),
                   mainPanel(
                     verbatimTextOutput(ns("mutation"))
                   )
                 )
        )
      )
    )
  )
}

##### Module server function #####
cellLineSelector <- function(input, output, session) {
  
  # restrict the choices of available mutations based on the cell lines with available gene expression data in the selected project
  mutations <- reactive({
    # check if input is specified - if not stop executing the rest of this code block
    req(input$project)
    
    if (input$project== 'abc') {
        mutation_list <- rep("a",10)
      
    }
    else{ 
        mutation_list <- rep("d",10)
    }
    return(list("mutation_list"=mutation_list))
  })
  ### I want to follow the changes of mutations()$mutation_list
  ### as a workaround I can output it directly to the app but I want to just print the content to the console
  output$mutation <- renderText({
    mutations()$mutation_list
  })
  
  return(list(mut=mutations)  
  )
}
##### Main app #####
ui <- fluidPage(title="Test",
  cellLineSelectorUI("test")
                
)
server <- function(input, output, session) {
  ret <- callModule(cellLineSelector, "test")
  ### How can I now print the value of ret()$mut ?
  print(ret()$mut)
}

shinyApp(ui = ui, server = server)

I found a solution now. Wrap the print in an observe function:

server <- function(input, output, session) {
  ret <- callModule(cellLineSelector, "test")
  ### How can I now print the value of ret()$mut ?
  observe(print(ret$mut()$mutation_list))
}

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