Not able to remove respective files

Hi all, in the below code, I am not able to remove the respective files (moment I click on remove button). PLease help me

library(shinydashboard)
library(readxl)
library(shiny)
out <- data.frame(baseFns = ls('package:base'))
ui <- dashboardPage(
  dashboardHeader(title = "Loading data"),
  dashboardSidebar(sidebarMenu(
    menuItem("Load Data", tabName = "Load_Data", icon = icon("balance-scale")),
    menuItem("Analysis", tabName = "Analysis", icon = icon("chart-bar"))
  )),
  dashboardBody(
    tabItems(tabItem(tabName = "Load_Data", numericInput("T", "No of data sets", value = 1, min = 1, width = 150),
                     # textInput("T", "No of data sets", value = 0,width = 150),
                     fluidRow(tags$div(id = "container")),
                     fluidRow(tags$div(id = "remove")),
                     fluidRow(box(title = "Dataset",uiOutput("filter_70"),width = 5000)))
    ))
)

server <- function(input,output){
  observe({
    req(input$T)
    removeUI("#fileInputContainer")
    removeUI("#remove1")
    insertUI("#container", "afterBegin", tags$div(id = "fileInputContainer"))
    insertUI("#remove", "afterBegin", tags$div(id = "remove1"))
    for(i in 1:input$T) {
      insertUI("#fileInputContainer", "beforeEnd",
               box(fileInput(paste0("dataFile", i), "Choose the csv file",
                             accept = c("text/csv","text/comma-separated-values,text/plain",".csv")),width = 2,height = 100))
    }
    for(i in 1:input$T) {
      insertUI("#remove1", "beforeEnd",
               box(actionButton("remove","remove",width = 140),width = 2))
    }
  })
  observeEvent(input$remove,{
    removeUI(selector = "#dataFile",immediate = TRUE)
  }) 
  
output$contents <- renderTable({
file_to_read <- input$dataFile
if(is.null(file_to_read))
return(NULL)
a <- read.csv(file_to_read$datapath)
head(a,n=15)
})

last_selected <- reactiveVal(NA)

observeEvent(input$dataFile, {
  last_selected("csv")
})

output$filter_70 <- renderUI({
  req(last_selected())
  if (last_selected()=="csv") {
    tableOutput("contents")
  } 
})
}
shinyApp(ui, server)

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