Hello again. Hope somebody in here's a college basketball nerd...
I'm back and dealing with some confusion about where I need to add my reactive
call in a Shiny app so that it follows a command to output a different plot depending whether input$playerSelector
is NA or non-NA.
The first output in the server call is the troublesome one. I don't know if I picked a bad place for my reactive
or if I'm just asking too much of the program with my case_when
that changes the plot type based on the NA status of input$playerSelector
library(extrafont)
library(shiny)
library(tidyverse)
library(ncaahoopR)
# Define UI for application
ui <- fluidPage(
# Application title
titlePanel("KU Dashboard"),
# Sidebar with a checkbox input for game selection
sidebarLayout(
sidebarPanel(
checkboxGroupInput("dateBoxes",
label = "Games to Include:",
choices = c("11-5 vs. Duke" = 401168155,
"11-8 vs. UNCG" = 401169601,
"11-15 vs. Monmouth" = 401169615,
"11-19 vs. ETSU" = 401169621 ,
"11-25 at Chaminade" = 401169630,
"11-26 vs. BYU" = 401182627,
"11-27 vs. Dayton" = 401182629,
"12-7 vs. Colorado" = 401169646 ,
"12-10 vs. Milwaukee" = 401169649,
"12-14 vs. UMKC" = 401169657,
"12-21 at Villanova" = 401169661,
"12-29 at Stanford" = 401169669
),
selected = c(401168155, 401169601, 401169615,
401169621, 401169630, 401182627,
401182629, 401169646, 401169649,
401169657, 401169661, 401169669
)
),
# Radio button input for weighting 3-pointers
radioButtons("weightButton",
label = "ASSIST NETWORK OPTIONS \n
Weighted 3-pointers?",
choices = c("Yes" = TRUE,
"No" = FALSE),
selected = TRUE
),
# Numeric input box for involvement threshold
numericInput("thresholdSelector",
label = "Minimum Involvement % for Player Inclusion?",
min = 0,
max = 1,
step = 0.01,
value = 0.1
),
#Selection input box for highlighting a player
selectInput("playerSelector",
label = "Player to highlight?",
choices = c("None" = NA,
"0 - Marcus Garrett" = "Marcus Garrett",
"1 - Devon Dotson" = "Devon Dotson",
"2 - Christian Braun" = "Christian Braun",
"3 - Dajuan Harris" = "Dajuan Harris",
"4 - Isaiah Moss" = "Isaiah Moss",
"5 - Elijah Elliott" = "Elijah Elliott",
"10 - Jalen Wilson" = "Jalen Wilson",
"12 - Chris Teahan" = "Chris Teahan",
"13 - Tristan Enaruna" = "Tristan Enaruna",
"20 - Michael Jankovich" = "Michael Jankovich",
"22 - Silvio De Sousa" = "Silvio De Sousa",
"30 - Ochai Agbaji" = "Ochai Agbaji",
"33 - David McCormack" = "David McCormack",
"35 - Udoka Azubuike" = "Udoka Azubuike",
"44 - Mitch Lightfoot" = "Mitch Lightfoot"),
selected = "None"),
#Radio button input for presenting shot chart as heatmap
radioButtons("heatmapSelector",
label = "SHOT CHART OPTIONS \n
Heatmap?",
choices = c("Yes" = TRUE,
"No" = FALSE)
)
),
# Show a plot of the generated distribution
mainPanel(
fluidRow(
plotOutput("assistNetworkPlot")
),
fluidRow(
plotOutput("kuShotChart"),
plotOutput("oppShotChart")
)
)
)
)
# Define server logic required to draw plots
server <- function(input, output) {
output$assistNetworkPlot <- reactive({
case_when(
!is.na(input$playerSelector)~
renderPlot({
circle_assist_net(team = "Kansas",
season = input$dateBoxes,
three_weights = input$weightButton,
threshold = input$thresholdSelector,
highlight_player = input$playerSelector,
highlight_color = "#0051BA")
}),
is.na(input$playerSelector)~
renderPlot({
assist_net(team = "Kansas",
node_col = "royalblue4",
season = input$dateBoxes,
three_weights = input$weightButton,
threshold = input$thresholdSelector,
message = "ASSIST NETWORK")
})
)
})
output$kuShotChart <- renderPlot({
team_shot_chart(game_ids = input$dateBoxes,
team = "Kansas",
heatmap = input$heatmapSelector)
})
output$oppShotChart <- renderPlot({
opp_shot_chart(game_ids = input$dateBoxes,
team = "Kansas",
heatmap = input$heatmapSelector)
})
}
# Run the application
shinyApp(ui = ui, server = server)