ReactiveUI 基于 ReactiveUI 的问题

标签 r shiny

我的代码如下,演示站点在这里:http://glimmer.rstudio.com/kdavenport/test1/

第一个输入(下拉菜单)加载在global.R中定义的数据框

第二个输入(下拉列表)通过 df 的“Service”列过滤此数据框

第三个输入(复选框)通过 df 的“Round”列进一步过滤数据框

问题在于,显示了第一步中数据帧可用的所有复选框,而不是步骤 2 中按“服务”过滤后可用的复选框。下面我有 1. clientData > serviceFiltered_clientData > roundFiltered_clientData

shinyServer(function(input, output) {

  # First UI input (Service column) filter clientData 
  output$serviceControls <- renderUI({
    if (is.null(clientData()))
      return("No client selected")
    selectInput("service_select", 
                "Choose Service:", 
                choices = as.character(levels(clientData()$Service.Name)),
                selected = input$service_select
    )
  })

  # Second UI input (Rounds column) filter service-filtered clientData  
  output$roundControls <- renderUI({
    if (is.null(serviceFiltered_clientData()))
      return("No service selected")
    checkboxGroupInput("round_select", 
                       "Choose Round:", 
                       choices = as.character(levels(serviceFiltered_clientData()$Round)))
  })  

  # First data load (client data)
  clientData <- reactive({
    if (is.null(input$client_select))
      return(NULL)
    get(input$client_select)
  })

  # Second data load (filter by service column)
  serviceFiltered_clientData <- reactive({
    dat <- clientData()
    if (is.null(dat))
      return(NULL)
    if (!is.null(input$service_select)) # !
      dat <- dat[dat$Service.Name %in% input$service_select,]
    return(dat)
  })

  # Third data load (filter by round column)
  roundFiltered_clientData <- reactive({
    dat <- serviceFiltered_clientData()
    if (is.null(dat))
      return(NULL)
    if (!is.null(input$round_select)) # !
      dat <- dat[dat$Round %in% input$round_select,]
    return(dat)
  })


  # Audit count panel
  output$auditsCount <- renderText({
    if (is.null(roundFiltered_clientData()))
      return("No client selected")
    paste("Total Audits:",nrow(roundFiltered_clientData()))
  })

最佳答案

react 性菊花链一直在工作,问题在于“Round”列作为因子加载,并且因子在子集化后仍作为数据框属性保留。因此,我需要在对数据进行子集化后使用 droplevels() 。我添加了dat <- droplevels(dat)如下:

  # Second data load (filter by service column)
  serviceFiltered_clientData <- reactive({
    dat <- clientData()
    if (is.null(dat))
      return(NULL)
    if (!is.null(input$service_select)) # !
      dat <- dat[dat$Service.Name %in% input$service_select,]
    dat <- droplevels(dat) # This is what fixed it
    return(dat)
  })

关于ReactiveUI 基于 ReactiveUI 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18660225/

相关文章:

r - 如何在 ggplot2 中围绕轴刻度标签创建一个框?

r - 设置 R 传单中图例文本的格式

r - 使用 >1000 个选项更新服务器端选择输入的选择失败

r - 修改函数以便控制流构造使用 `{...}` 并在正确的位置保留注释

r - 如何修复在 ShinyProxy 中获取 CSS 和 Javascript 文件时出现的 '404 (Not Found)' 错误

r - 使用带有 Shiny、R 和 future 的外部类

r - 从 Shiny 的R中的散点图的多个选择生成多个表

R Shiny 将 TextInput 的内容放入 sql 查询中

r - 让 shiny 的 `dateRangeInput` 的 `end` 总是大于 `start`

从 R 读取断开的 CSV 行