【发布时间】:2021-05-02 20:05:48
【问题描述】:
我在从用户获取输入后尝试读取文件 - 首先是日期,然后是文件选择,但我无法让代码读取任何文件并对其执行任何操作。错误消息如下。还有没有办法让这段代码更有效率?
ui <- fluidPage(
titlePanel("Select the execution date")
,dateInput("ME_DATE",label=h3("Execution Date Input"), value="2020-05-29")
,hr()
,fluidRow(column(3,verbatimTextOutput("Output_path")))
,hr()
,selectInput('selectfile','Select File in Above Location', choices=NULL)
,textOutput('fileselection_statement')
,tableOutput('selected_table')
)
server <- function(input, output, session) {
# Location for Outputs
Output_DIR <- "K:/Outputs/"
Output_loc <- reactive({
year_N_ME_DATE <- format(input$ME_DATE,"%Y")
month_N_ME_DATE <- format(input$ME_DATE,"%m")
month_T_ME_DATE <- months(input$ME_DATE)
file.path(paste(Output_DIR,month_N_ME_DATE,". ",month_T_ME_DATE, " ",year_N_ME_DATE,"/",sep=""))
})
# Output Path
output$Output_path <- renderPrint({ Output_loc() })
# files list
Updated_Output_files_list <- reactive({ list.files(Output_loc()) })
observeEvent(input$selectfile, {
updateSelectInput(session, "selectfile", choices=Updated_Output_files_list())
output$fileselection_statement <- renderText({paste0('You have selected: ', input$selectfile) })
})
selectfile <- reactive(get(input$selectfile))
output$selected_table <- renderTable({ read.csv(paste0(renderPrint({ Output_loc() }),renderPrint({ selectfile() }),sep="")) })
}
shinyApp(ui, server)
【问题讨论】:
-
observe块不输出任何内容,我认为您的file.path(..)不会去任何地方。也许您应该将该块转换为myfile <- reactive({...; file.path(.);}),然后再打开myfile()或类似的。 (在尝试读取文件之前,您可能会从req(file.exists(myfile()))中受益。) -
它一直工作到
output$fileselected,因为我可以看到“您已选择...”的选择,但无法显示内容。在file.path()上,Copied_Source_Files_loc不是从中获取价值吗? -
observe块不返回任何东西,所以当块确实评估file.path(.)时,它无处可去。 -
我取出观察器并更新代码如下,但仍然无法让它工作` output$selected_table
-
请edit您的问题和更改以反映您所做的更改。谢谢!