【问题标题】:R shiny, How to use selectInput function well?R 闪亮,如何很好地使用 selectInput 功能?
【发布时间】: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_categorychoices 参数中添加什么。

我尝试使用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 &lt;- renderPrint(input$larger) 和在 UI 中创建 verbatimTextOutput("d")

标签: r shiny reactive-programming


【解决方案1】:

调试

首先,您需要使用browser() 或打印值来调试和查看您的值,例如:

  • 在服务器output$d &lt;- renderPrint(input$larger)

  • 在用户界面verbatimTextOutput("d")

可能的问题

  • 如果未设置selectedselectInput 默认为单选列表的第一个值。

  • 如果FolderDir 是反应式的,它就会产生效果。

【讨论】:

  • 感谢您的回复!
猜你喜欢
  • 2015-05-07
  • 2023-04-06
  • 2020-08-24
  • 2015-01-15
  • 2016-07-28
  • 1970-01-01
  • 1970-01-01
  • 2018-11-28
  • 1970-01-01
相关资源
最近更新 更多