【问题标题】:How to filter() interactively a DT by choosing a criterion in a selectInput() and defining the a numericValue()如何通过在 selectInput() 中选择标准并定义 numericValue() 以交互方式过滤 DT
【发布时间】:2019-12-25 21:46:17
【问题描述】:

我正在尝试创建一个闪亮的应用程序,允许用户通过在 selectInput() 中选择一个数值变量和在 numericValue() 中选择一个数值来过滤数据表。 无论我尝试了什么,我都会出错

我尝试使用四种方式(input$y、get(input$y)、!!get(input$y)、!!sym(input$y))调用服务器函数中的变量,但没有得到预期结果。

server <- shinyServer(function(input, output){
    output$filteredtable <- DT::renderDataTable({
      newtab <- movies %>%
        dplyr::filter(!!sym(input$y) < !!sym(input$numValue))

      DT::datatable(data = newtab)
    })
  })

我希望表格对选择的输入和定义的数值做出交互反应。

input$y --> 给出一个与我们在 selectInput() 中选择的内容不交互的空表

get(input$y) --> 给出error: invalid first argument

!!get(input$y) --> 给出error: object 'runtime' not found('runtime' 是使用文件中的数字变量)。

!!sym(input$y) --> 给出error: Only strings can be converted to symbols

【问题讨论】:

标签: filter shiny dplyr shinydashboard


【解决方案1】:

当然@Thomas Fuchs

ui <- shinyUI(
    dashboardPage(
        dashboardHeader(), 
        dashboardSidebar(

          # Critère du filtre 
            selectInput(inputId = "y", 
                        label = "Choisir ici le critère du filtre : ", 
                        choices = c("runtime", "thtr_rel_day", "dvd_rel_year","critics_score", "audience_score"),
                        selected = "runtime"), 

          # Slider 
            numericInput(inputId = "numValue", 
                        label = "Choisir une valeur numérique pour le filtre", 
                        value ="500", 
                        min = 1, 
                        max = 1000,
                        step = 50, 
                        width = '100%')
        ), 

        # body 
        dashboardBody(
          fluidPage(
            box(DT::dataTableOutput(outputId = "filteredtable"), 
                title = "Les données filtrées")
          )
        )
    )
  )

【讨论】:

    猜你喜欢
    • 2013-04-16
    • 1970-01-01
    • 2021-08-22
    • 2021-01-22
    • 1970-01-01
    • 2021-03-04
    • 1970-01-01
    • 1970-01-01
    • 2019-07-13
    相关资源
    最近更新 更多