如何在 Shiny 中显示整行选定值?

How to display entire row of selected value in Shiny?

如何显示选中值的整行?

我们有一个下拉菜单,可以在其中选择已定义列的特定值。如果下拉菜单中的值之一被选中,则应显示该值所在的整行。

在以下情况下,可以在下拉菜单中选择的值是字母 x、y、z。例如如果在下拉菜单中选择了“y”,它应该只显示整个第二行,包括列名。

library(shiny)

Values <- data.frame(A = 1:3, B = letters[24:26], C = 11:13)

shinyApp(
ui = fluidPage(        
    sidebarPanel(
        selectInput("Values", "Values", Values$B),            
    mainPanel(
        tableOutput("ValuesTable")
        )
    )
),

server = function(input, output) {    
    output$ValuesTable <- renderTable({
        Values
    })    
})

到目前为止我发现的是 _rows_selected 的解决方案。但是,它不适合我的问题,或者我还不能使用它。

您可以使用 dplyr::filter()renderTable() 函数中的 select 输入“值”来过滤适当列中的值。

library(shiny)
library(dplyr) # for filter() function
library(magrittr) # for pipe operator

Values <- data.frame(A = 1:3, B = letters[24:26], C = 11:13)

shinyApp(
  ui = fluidPage(        
    sidebarPanel(
      selectInput("Values", "Values", Values$B),            
      mainPanel(
        tableOutput("ValuesTable")
      )
    )
  ),
  
  server = function(input, output) {    
    output$ValuesTable <- renderTable({
      Values %>% 
        dplyr::filter(B == input$Values)
    })    
  })