在闪亮的应用程序主体中显示一个文件夹结构,作为盒子而不是弹出
我想在我的Shiny应用程序中有一个盒子,用户可以浏览到文件夹结构并选择要下载的文件。 我已经尝试了shinyfiles
,但是文件选择是一个弹出窗口,我可以下载一个文件:
library(shiny)
library(shinyFiles)
ui <- fluidPage(
shinyFilesButton('files', label='File select', title='Please select a file', multiple=T) ,
verbatimTextOutput('rawInputValue'),
verbatimTextOutput('filepaths') ,
downloadButton("downloadFiles", "Download Files")
)
server <- function(input, output) {
roots = c(wd = 'H:/')
shinyFileChoose(input, 'files',
roots = roots,
filetypes=c('', 'txt' , 'gz' , 'md5' , 'pdf' , 'fasta' , 'fastq' , 'aln'))
output$rawInputValue <- renderPrint({str(input$files)})
output$filepaths <- renderPrint({parseFilePaths(roots, input$files)})
output$downloadFiles <- downloadHandler(
filename = function() {
as.character(parseFilePaths(roots, input$files)$name)
},
content = function(file) {
fullName <- as.character(parseFilePaths(roots, input$files)$datapath)
file.copy(fullName, file)
}
)
}
shinyApp(ui = ui , server = server)
” UI,不是新的(弹出)窗口!
I would like to have a box in my shiny app, which user can browse to a folder structure and select a file to download.
I have tried the shinyFiles
but the file selection is a pop-up window and I could just download a single file :
library(shiny)
library(shinyFiles)
ui <- fluidPage(
shinyFilesButton('files', label='File select', title='Please select a file', multiple=T) ,
verbatimTextOutput('rawInputValue'),
verbatimTextOutput('filepaths') ,
downloadButton("downloadFiles", "Download Files")
)
server <- function(input, output) {
roots = c(wd = 'H:/')
shinyFileChoose(input, 'files',
roots = roots,
filetypes=c('', 'txt' , 'gz' , 'md5' , 'pdf' , 'fasta' , 'fastq' , 'aln'))
output$rawInputValue <- renderPrint({str(input$files)})
output$filepaths <- renderPrint({parseFilePaths(roots, input$files)})
output$downloadFiles <- downloadHandler(
filename = function() {
as.character(parseFilePaths(roots, input$files)$name)
},
content = function(file) {
fullName <- as.character(parseFilePaths(roots, input$files)$datapath)
file.copy(fullName, file)
}
)
}
shinyApp(ui = ui , server = server)
What I would like is to have the file selection option like
within the ui, not as new (pop-up) window !
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是我在评论中谈到的应用程序的第一个版本。它的优势是,仅当用户选择此文件夹时,只有在使用第一个后代,没有加载文件夹的内容,而没有递归。
应用程序文件夹结构:
文件 global.r :
文件 server.r :
文件 ui.r.r :
文件 navigator.css :
文件 navigator.js :(
我是 jstreer 的作者,我想我会做一个 包含在软件包中。
的
此文件夹导航器
闪亮模块并将其 i.sstatic.net/kngwy.gif“ rel =“ nofollow noreferrer”>
”使用此应用程序,您首先需要包装的更新版本:
三个文件中有一些更改:
编辑2
该软件包的新版本提供了一个闪亮的模块,可方便地渲染这样的“树导航器”(甚至几个)。这是软件包中给出的示例:
Here is a first version of the app I talked about in my comment. Its advantage is that the contents of a folder are loaded only when the user selects this folder, and only the first descendants are loaded, no recursion.
App folder structure:
File global.R:
File server.R:
File ui.R:
File navigator.css:
File navigator.js:
(I am the author of jsTreeR and I think I will do a Shiny module for this folder navigator and include it in the package.)
EDIT
I improved the app and it uses the proton theme now, which looks more pretty to me:
To use this app, you first need the updated version of the package:
There are some changes in three files:
EDIT 2
The new version of the package provides a Shiny module allowing to conveniently renders such a 'tree navigator' (or even several ones). This is the example given in the package: