My goal is merging datasets from users, the users will upload 2 datasets and merge,if they want to merge another one, I stored the one just merge and insert another module, and keep going. I try to approach by inserting a module in another module. I don't know what I am doing wrong, it didn't give me the output the module I inserted. It need to be done in the modules.
I would be grateful for any help as I have been stuck on this for a while.
Code to reproduce the above:
require(shiny)
require(shinyFiles)
#===========================================================
uploadDtUI <- function(id){
ns <- NS(id)
tagList(
shinyFilesButton(ns("file_2"), "Select The The Second Dataset", "Please Select The Second Dataset",FALSE),
verbatimTextOutput(ns("filechosen_new"))
)
}
uploadDt <- function(input, output, session) {
ns <- session$ns
roots = c(getVolumes()())
shinyFileChoose(input,"file_2",session = session,root = roots)
file_new <- reactive(input$file_2)
output$filechosen_new <- renderPrint({
as.character(parseFilePaths(roots, input$file_new)[4])
})
}
#=============================================================
selectFilesInput <- function(id) {
ns <- NS(id)
tagList(shinyFilesButton(ns("file"), "Select The First Dataset", "Please Select The First Dataset",FALSE),
verbatimTextOutput(ns("filechosen")),
actionButton(ns("add_ui"), "Add Another Dataset to Merge"),
div(id = ns("placeholder"))
)
}
selectFiles <- function(input, output, session) {
ns <- session$ns
vol <- c(getVolumes()())
shinyFileChoose(input,"file",session = session,root = vol)
file <- reactive(input$file)
output$filechosen <- renderPrint({
as.character(parseFilePaths(vol, input$file)[4])
})
ctn <- reactiveVal(0)
observeEvent(input$add_ui, {
ctn(ctn() + 1)
new_id <- paste("module", ctn(), sep="_")
insertUI(
selector = paste0('#', ns('placeholder')),
where = "afterBegin",
ui = uploadDtUI(ns(new_id))
)
callModule(uploadDt,ns(new_id))
})
}
#=============================================================
ui <- fluidPage(
selectFilesInput("foo")
)
server <- function(input, output, session) {
datafile <- callModule(selectFiles, "foo")
}
shinyApp(ui, server)