I have an app that displays a data frame of NBA statistics organized by team and player. When the user selects a team, a data frame of the statistics for the best players from that team are displayed. When the user selects a player, a data frame of the statistics for the player is displayed.
All 30 NBA teams are displayed in selectInput. When a team is chosen, a different selectInput offers displays a list of certain players from that team. There's a tab for the dataframe that displays a list of players and a tab that solely displays a single player's statistic.
How can I make it so that, once a user selects a player, the app updates to the player tab? What I am doing currently with observeEvent does not work. I tried using observe with input$var1 but I was receiving an "argument is of length zero" error.
See the tabs here, https://binlee.shinyapps.io/test_app/
# ui.R
shinyUI(fluidPage(
titlePanel("My App"),
sidebarLayout(
sidebarPanel(
uiOutput("teamInput")
, uiOutput("playerInput")),
mainPanel(
tabsetPanel(
tabPanel("Team", tableOutput("table")),
tabPanel("Player", tableOutput("table1"),
id = "panelTabs")
)))))
df <- read.csv("data.csv", header = TRUE, stringsAsFactors = FALSE)
# server.R
shinyServer(
function(input, output, session)
{output$teamInput <- renderUI({selectInput("var",
label = "Choose Team",
choices = c(unique(df$Team)),
selected = "unique(df$Team)")})
output$table <- renderTable({df[df$Team == input$var,4:14]})
output$playerInput <- renderUI({selectInput("var1",
label = "Choose Player",
choices = df[df$Team == input$var, 4])})
observeEvent(input$var1,
{updateTabsetPanel(session, inputId="panelTabs", selected="Player")})
output$table1 <- renderTable({df[df$Name == input$var1, 4:14]})
})