【发布时间】:2017-02-28 07:15:44
【问题描述】:
我有文件夹(A、B、C)和文件(a、b、c)。这些文件夹都在同一个目录中。
每个文件夹都有所有文件。
示例:FolderA 有文件(A-a,A-b,A-c),FolderB 有文件(B-a,B-b,B-c),FolderC 有文件(C-a,C-b,C-c)。
所以,我想显示这些列表。
这是我想要的输出:
当我选择文件夹 B 时,我想在 (Smaller Category)-selectInput 上显示文件夹 B 的文件列表。如果我按下操作按钮,我想使用响应函数来处理该路径的数据(文件夹 B/CsvFile B-c)。
global.R
getFromGlobalR <- memoise(function(path){
execution code...
}
ui.R
fluidPage(
titlePanel("selectInput"),
fluidRow(
uiOutput("larger_category"),
uiOutput("smaller_category"),
uiOutput("action_btn")
)
)
server.R
executed_statement <- reactive({
input$action_btn
isolate({
if(input$smaller=="") return()
getFromGlobalR(input$smaller)
})
})
output$larger_category <- renderUI({
selectInput("larger", "select folder", choices =list.dirs(path = "./FolderDir", full.names = FALSE, recursive = FALSE))
})
output$smaller_category <- renderUI({
selectInput("smaller", "select files", choices = ?)
})
output$action_btn <- renderUI({
actionButton("actionBtn", class="btn-primary", "search")
})
我不知道在output$smaller_category 的choices 参数中添加什么。
我尝试使用choices=list.files(paste("./",input$larger,sep=""), ".csv")。但是没用。
另外,即使我把choices 参数放在output$smaller_category 中,我也不知道它是否能正常工作。
有什么想法吗?
【问题讨论】:
-
那么你得到了什么?您是否能够填充较小的 selectInput,但不确定它们是否属于正确的目录?还是您无法用第一名的值填充它?
-
文件夹都在同一个目录下。我不知道如何将较大的 selectInput 填充到较小的 selectInput。
-
首先尝试打印
input$larger进行调试,我认为这是可行的。那你为什么要粘贴“.csv”,list.files应该返回名字.csv -
当我打印
input$larger in server.R.时出现错误警告:.getReactiveEnvironment()$currentContext 中的错误:没有活动的反应上下文不允许操作。 (你试图做一些只能从反应式表达式或观察者内部完成的事情。)` -
使用 browser(),或者在服务器中创建
output$d <- renderPrint(input$larger)和在 UI 中创建verbatimTextOutput("d")
标签: r shiny reactive-programming