【发布时间】:2021-08-04 05:21:30
【问题描述】:
我目前正在运行一个应用程序,它描绘了一张 NBA 球队及其表现指标的表格。 “nba”数据包含联盟中每支球队的 30 行以及 26 列不同的指标和描述,例如“球队”、“会议”、“REC”和“PTS”。用户可以通过 checkboxGroupInput 选择这些性能指标。我正在尝试为团队会议添加一个过滤器。这将是一个 selectInput 函数。如果用户选择东部,我希望输出返回一个只有东部会议团队的表格。如果用户选择西部,我希望输出返回一个只有西部球队的表格。我不知道该怎么做。我尝试输入 'input$conference' 代替 'nba' 和其他技术,但没有任何效果。我希望有人能帮帮忙。这是我的代码:
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)```
【问题讨论】:
标签: r shiny selectinput