【发布时间】:2017-12-08 17:21:01
【问题描述】:
我希望我的 Shiny 应用程序允许用户指定文件夹的路径(本地)并显示选定的路径。以下代码有效,但在选择文件夹之前,我无法弄清楚如何在 verbatimTextOutput 中隐藏“character(0)”。我尝试了条件面板(请参阅我的代码中的注释),但无法确定在这里使用什么作为条件(因为 shinyDirButton 不是标准操作按钮......)。谢谢!
library(shiny)
library(shinyFiles)
# Define UI for application that draws a histogram
ui <- fluidPage(
# Application title
mainPanel(
shinyDirButton("dir", "Input directory", "Upload"),
#conditionalPanel(
#condition = "???",
verbatimTextOutput('dir')
#)
)
)
server <- function(input, output) {
shinyDirChoose(input, 'dir', roots = c(home = '~'), filetypes = c('', 'txt','bigWig',"tsv","csv","bw"))
dir <- reactive(input$dir)
output$dir <- renderPrint({parseDirPath(c(home = '~'), dir())})
observeEvent(
ignoreNULL = TRUE,
eventExpr = {
input$dir
},
handlerExpr = {
home <- normalizePath("~")
datapath <<- file.path(home, paste(unlist(dir()$path[-1]), collapse = .Platform$file.sep))
}
)
}
# Run the application
shinyApp(ui = ui, server = server)
我能找到的最接近的问题是这个,但它不能解决我的问题:R conditionalPanel reacts to output
【问题讨论】: