I am trying to use the combination of Action Button and InsertUI to help the user input excel Files. Once the user clicks on the button, the FileInput box should appear (I will then handle the fileinput$datapath later to create a dataframe.)
In the code below, I try to:
library(shiny)
Import.Excel.Data.UI <- function(id){
ns <- NS(id)
tagList(
actionButton(ns("AddExcelDataButton"), label = "Click Here to Add Excel Data"),
)
}
Import.Excel.Data.Server <- function(id){
moduleServer(id, function(input, output, session){
ns <- session$ns
observeEvent(eventExpr = input$AddExcelDataButton,
insertUI(selector="#AddExcelDataButton",
where = "afterEnd",
ui = fileInput(inputId = paste0("File",input$AddExcelDataButton),
label = paste0("Path for File",input$AddExcelDataButton),
multiple = FALSE)))
})
}
Import.Excel.Data.App <- function(){
ui <- fluidPage(
Import.Excel.Data.UI("File1")
)
server <- function(input, output, session){
Import.Excel.Data.Server("File1")
}
shinyApp(ui, server)
}
Import.Excel.Data.App()
You need to use the namespace:
insertUI(selector=paste0("#", ns("AddExcelDataButton")), ......