[英]R Shiny select files from server-side directory
I have a folder called logs
filled with different .csv
files, formatted as telemetryLog-2017.21.08.54.11.csv
(with varying dates and times at end). 我有一个名为logs
的文件夹,其中充满了不同的.csv
文件,格式为telemetryLog-2017.21.08.54.11.csv
(末尾的日期和时间各不相同)。
For example, the above file could be stored like this: file <- read.csv("logs/telemetryLog-1969.2017.21.08.54.11.csv", header=TRUE)
例如,上面的文件可以这样存储: file <- read.csv("logs/telemetryLog-1969.2017.21.08.54.11.csv", header=TRUE)
The log files would be uploaded (in the logs
folder, to shinyapps.io
) along with the ui.R
and server.R
files. 日志文件将与ui.R
和server.R
文件一起上载(在logs
文件夹中,到shinyapps.io
)。 I would like to be able to obtain a list of the filenames in order to be able to select a file to display as data in a plot via selectInput
(or any other way to list the files). 我希望能够获取文件名列表,以便能够通过selectInput
(或任何其他列出文件的方式)选择要在图表中显示为数据的文件。 The amount of files in the folder will not be an excessive amount; 文件夹中的文件数量不会过多。 most likely it will be limited to around 50. 最有可能将其限制在50个左右。
I have read the documentation for shinyFiles
and to be completely honest I do not fully understand how the commands such as fileGetter
or dirGetter
work. 我已经阅读了shinyFiles
的文档,说实话,我还不完全了解fileGetter
或dirGetter
等命令的工作方式。 Any help would be appreciated. 任何帮助,将不胜感激。
Instead of having people browse the file system of your server, you could also use list.files
and specify the right directory there: 除了让人们浏览服务器的文件系统外,您还可以使用list.files
并在list.files
指定正确的目录:
library(shiny)
ui <- fluidPage(
selectInput('selectfile','Select File',choice = list.files('log/')),
textOutput('fileselected')
)
server <- function(input,output)
{
output$fileselected <- renderText({
paste0('You have selected: ', input$selectfile)
})
}
shinyApp(ui,server)
Hope this helps! 希望这可以帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.