首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >RShiny - selectInput + renderTable过滤

RShiny - selectInput + renderTable过滤
EN

Stack Overflow用户
提问于 2021-05-14 07:42:46
回答 1查看 16关注 0票数 0

我目前有一个正在运行的应用程序,它描绘了一个NBA球队及其表现指标的表格。“nba”数据包含联盟中每支球队的30行,以及26列不同的度量和描述,如“球队”、“会议”、“REC”和“PTS”。用户可以通过checkboxGroupInput选择这些性能指标。我正在尝试为团队会议添加一个过滤器。这将是一个selectInput函数。如果用户选择东部,我希望输出返回一个表,其中只包含来自东部会议的团队。如果用户选择西部,我希望输出返回一个表,其中只包含来自西部的球队。我不知道该怎么做。我试着输入'input$conference‘来代替'nba’和其他技术,但是什么都没有用。我希望有人能帮上忙。下面是我的代码:

代码语言:javascript
复制
library(shiny)
library(ggplot2)
library(jsonlite)
nba <- read.csv(file.choose())
head(nba)
Eastern = filter(nba,Conference=="Eastern")
Western = filter(nba,Conference=="Western")

ui <- fluidPage(
    tags$img(height=150, width=830,src = "NBAlogo2.png"),
    tabsetPanel(
        # General
        tabPanel(title = "General",
                 titlePanel("NBA Team Performance Metrics Analysis"),
                 sidebarLayout(
                     sidebarPanel(
                         p("This application allows you to compare and contrast several performance metrics amongst teams in the NBA."),
                         tags$img(height=100, width=100,src = "Eastern.png",align="center"),
                         tags$img(height=100, width=100,src = "Western.png"),
                         
                         # Team Filter
                         selectInput("conference", label = h3("Select Conference"),
                                     choices = list("Eastern", "Western")),

                         # Stat Filter
                         checkboxGroupInput("general", label = h3("General Metrics"), 
                                            choices = list("Winning Percentage" = "REC",
                                                           "Points" = "PTS")),
                     ),
                     mainPanel(
                         # Metric Output
                         h3("General Metrics"),
                         tableOutput("data1"),
                     ),
                 )
        )        
    )
)

server <- function(input, output) {
   
    #  General
    output$data1 <- renderTable({nba[,c("Team",input$general)]},
                                rownames = TRUE)
}

shinyApp(ui = ui, server = server)```
EN

回答 1

Stack Overflow用户

发布于 2021-05-14 13:32:49

你是说像这样吗?

代码语言:javascript
复制
library(shiny)
library(dplyr)

server <- function(input, output) {
  #  General
  output$data1 <- renderTable({
    nba %>%
      filter(Conference == input$conference) %>%
      select(Team, input$general)
  })
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67527467

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档