当文件上传到“file2”中时,我正在尝试更新过滤器(“maletablepercent”)。过滤器应该对文件输入“file2”中的更改做出反应。此外,fileinput 应该支持多次上传。我尝试使用以下代码,但没有任何反应。
ui <- fluidPage(id = 'test',
theme = shinytheme("darkly"),
title = "Experience Analysis Reporting",
fluidRow(column(6,fileInput("file1", "Select ES Output", width = "600px")),column(6,fileInput("file2", "Select Tables",multiple=TRUE, width = "600px")),column(2,selectInput("maletablepercent", "Male :%Table", "84.5")),column(2,pickerInput(inputId = 'maletable',label = 'Male Mortality Table', choices = "",
options = list(`style` = "btn-warning")))))
server <- function(input, output,session) {exp_data<-reactive({
browser()
if(length(grep("xlsx",input$file1$datapath))>0){
#browser()
df<-openxlsx::read.xlsx(input$file1$datapath,sheet="Consolidated Data")
}
if(length(grep("csv",input$file1$datapath))>0){
#browser()
df<-data.table::fread(input$file1$datapath)}
df
})
base_data<-reactive({ if(length(grep("xlsx",input$file2$datapath[[1]]))>0){
# browser()
impdata<-data.frame(matrix(ncol = 4, nrow = 0))
colnames(impdata)<-c("AGE","TABLE","MALE","FEMALE")
for(nr in 1:length(input$file2[, 1])){
file1 <- openxlsx::read.xlsx(input$file2[[nr, 'datapath']],sheet=substr(input$file2$name[[nr]],1,nchar(input$file2$name[[nr]])-5))
file1<-file1%>%mutate(Table=substr(input$file2$name[[nr]],1,nchar(input$file2$name[[nr]])-5))
colnames(file1)<-c("AGE","MALE","FEMALE","TABLE")
impdata<-rbind(impdata,file1)
impdata
}}
})
observe({y<-base_data()
x<-data.frame(unique(y$TABLE))
updateSelectInput(session, "maletablepercent", choices=unique(x),selected = x$TABLE[1])
})}
shinyApp(ui, server)
谢谢你的帮助,赫马