0

I currently have an application running where it portrays a table of NBA teams and their performance metrics. The 'nba' data contains 30 rows with each team in the league as well as 26 columns of different metrics and descriptions such as 'Team', 'Conference', 'REC', and 'PTS'. The user is able to pick these performance metrics through a checkboxGroupInput. I am trying to add a filter in for the Conference of the teams. This would be a selectInput function. If the user chooses Eastern, I would like the output to return a table with only teams from the Eastern conference. If the user chooses Western, I would like the output to return a table with only teams from the Western Conference. I am not sure how to do this. I have tried inputting 'input$conference' in place of 'nba' and other techniques, but nothing has worked. I hope someone can help. Here is my code:

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)```
Ronak Shah
  • 377,200
  • 20
  • 156
  • 213
WillyG
  • 1
  • 1

1 Answers1

0

Do you mean like this?

library(shiny)
library(dplyr)

server <- function(input, output) {
  #  General
  output$data1 <- renderTable({
    nba %>%
      filter(Conference == input$conference) %>%
      select(Team, input$general)
  })
}
Ronak Shah
  • 377,200
  • 20
  • 156
  • 213