【发布时间】:2019-10-25 21:51:37
【问题描述】:
我对 R/Rshiny/RMarkdown 很陌生,我已经使用了一些基本的用户输入模板来构建应用程序。我想要的是用户输入文件路径并能够在另一个函数/块中调用文件名和文件路径。
我发现响应式可能是执行此操作的关键功能,但我不确定如何使用它。
library(shinyFiles)
ui <- fluidPage(
shinyFilesButton("Btn_GetFile", "Choose a file" ,
title = "Please select a file:", multiple = TRUE,
buttonType = "default", class = NULL),
textOutput("filename"),
textOutput("txt_file")
)
filepath <- reactiveValues() #trying, but this isn't quite working
server <- function(input,output,session){
volumes = getVolumes()
observe({
shinyFileChoose(input, "Btn_GetFile", roots = volumes, session = session)
if(!is.null(input$Btn_GetFile)){
# browser()
file_selected<-parseFilePaths(volumes, input$Btn_GetFile)
output$txt_file <- renderText(as.character(file_selected$datapath))
output$filename <- renderText(as.character(file_selected$name))
filepath <- reactive({output$txt_file}) #an attempt, but it isn't doing what I want.
}
})
}
shinyApp(ui = ui, server = server)
isolate(filepath) #also tried print. Really just trying to see if filepath is populated
如果用户输入 /Users/Jim/tmp.txt,我希望看到 UI 显示 /Users/Jim/tmp.txt 和 tmp.txt(它确实如此)并且还看到 /Users/Jim/ tmp.txt 被存储为我可以在其他地方访问的文件路径变量。
【问题讨论】:
标签: r shiny markdown r-markdown