1

I have been studying the following question.

here

However, I am stuck on a variation of the problem:

I am trying to pass only certain values (vals) from the inputModule to the outputModule.
However, my inputModule also has an additional rendered output. This seems to be preventing the app from working.
I my real life app, the inputModule needs to pass data to a nested (outputmodule) and produces additional output and UI as well.

How can I restrict callModule or MyImProxy to only the vals and not pass output$mytext to my outputModule in the app server call?

Is is possible to have this code run while keeping the output$mytext in the inputModule`?

Many thanks

library(shiny)

inputModuleUI <- function(id){
          ns <- NS(id)
          wellPanel(h3("Input Module"),
                    textInput(ns('text1'), "First text"),
                    textInput(ns('text2'), "Second text"), 
                    textInput(ns('text3'), "Third text")
                    ), 
          
          verbatimTextOutput(ns("mytext"))
}

inputModule <- function(input, output, session){
          vals <- reactiveValues()
          observe({vals$text1 <- input$text1})
          observe({vals$text2 <- input$text2})
          return(vals)
          
    #I need this output to stay in the inputModule
          
          output$mytext <- renderPrint({
                    
                    paste(input$text3)
                    
          })
          
          
          
}

outputModuleUI <- function(id){
          tagList(
                    inputModuleUI('IM'),
                    wellPanel(h3("Output Module"),
                              verbatimTextOutput(NS(id, "txt")))
          )
}
outputModule <- function(input, output, session, ImProxy){
          output$txt <- renderPrint({
                    paste(ImProxy$text1, "&", ImProxy$text2)
          })
}

ui <- fluidPage(
          outputModuleUI('OM')
)   
server <- function(input, output, session){
    
#here is where I need to only pass vals to MyImProxy...

          MyImProxy <- callModule(inputModule, 'IM') 
          callModule(outputModule, 'OM', MyImProxy)
}

shinyApp(ui, server) ```

mdb_ftl
  • 423
  • 2
  • 14

1 Answers1

1

Your problem lies in the inputModuleUI. If you combine several ui elements, wrap it with tagList:

inputModuleUI <- function(id){
      ns <- NS(id)
      tagList(
      wellPanel(h3("Input Module"),
                textInput(ns('text1'), "First text"),
                textInput(ns('text2'), "Second text"), 
                textInput(ns('text3'), "Third text")
      ), 
      
      verbatimTextOutput(ns("mytext"))
      )
}
starja
  • 9,887
  • 1
  • 13
  • 28
  • That works thank you! but I have a second question - how could I put the inputModuleUI into the outputModuleUI - why doesn't this work? I have edited the original question – mdb_ftl Mar 05 '21 at 16:39
  • I think for this you have to directly call the `inputModule` server function within the `outerModule` server function and also assign the returned values there – starja Mar 05 '21 at 16:58