'lapply in return Shiny Module

I have the list of variables and some more stuffs. When I submit the information from the user, I used lapply to apply the module updateServer. Inside the module the user is able to edit the information, and it will save after the user click update button. The module return a dataframe.

How I can return the list of dataframes in the server after I call the Module?

MODULE return dt


# Module
updateUI <- function(id){
    ns <- NS(id)
    tagList(
        uiOutput(ns("title_out")),
        uiOutput(ns("x_label_out")),
        uiOutput(ns("y_label_out")),
        uiOutput(ns("sb_edit"))
    )
}
updateServer <- function(input, output, session, title_plot) {
    ns <- session$ns
    values <- reactiveValues(title = "",x_label = "", y_label = "")
    
    output$title_out <- renderUI({
        textInput(ns("title"), "Title", value = paste0("This is a title for ",title_plot))
    })
    
    
    output$x_label_out <- renderUI({
        textInput(ns("x_label"),"X Label", value = "")
    })
    
    
    output$y_label_out <- renderUI({
        textInput(ns("y_label"), "Y Label", value = "")
    })
    
    output$sb_edit <- renderUI({
        actionButton(ns("update"), "Update")
    })
    
    
    observeEvent(input$update,{
        values$title <- input$title 
        values$x_label <- input$x_label 
        values$y_label <- input$y_label 
    })
    
    dt <- reactive({
        dt <- data.frame(title = values$title, x_label = values$x_label, y_label = values$y_label)
    })
    
    return(list(dt = dt()))
}

SERVER


library(shiny)
# server
shinyServer(function(input, output) {
    
    var <- eventReactive(input$sb,{
        input$var 
    })
    
    handlers <- list()
    
    observe({
        handlers <<- lapply(var(), function(i){callModule(updateServer, paste0("test_",i), i) })
    })
    
    output$ui_out <- renderUI({
        lapply(var(), function(i){
            tagList(updateUI(paste0("test_",i)))
        })
    })
    
    
    # Return the list here
    output$out <- renderText({ ## 7
        req(length(handlers) > 0)
        out <- lapply(handlers, function(h) h$dt())
    }) 
})

UI

# ui

library(shiny)

shinyUI(fluidPage(
    sidebarLayout(
        sidebarPanel(
            tagList(
            selectInput("var", "Variables for Plot",choices = names(mtcars), selected = names(mtcars)[1:3], multiple = T),
            actionButton("sb", "Submit")
            )
        ),

        mainPanel(
            uiOutput("ui_out"),
            verbatimTextOutput("out")
        )
    )
))




Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source