I have the shiny app below in which the user selects the inputs from the 2 widgets in tabpanel ONE
and Number of drills
and Select Players for Training Session
. If Number of Drills==1
then the table in tabPanel TWO
is displayed else if Number of Drills==2
the table in tabPanel THREE
is displayed. The issue is that I want both tables to be permanently displayed and not disappear according to the selection mentioned above while keeping the reactivity based on the selection mentioned above. If this is not possible then would it be possible to replace the conditional panel logic with another method? Maybe with renderUI()
that would create reactive panels?
## app.R ##
library(shiny)
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(
),
dashboardBody(
tabItem(tabName = "data_table",
h2("Data Table"),
h4("Below is a searchable table of all data used in this project."),
tableOutput("all_data_table")
),
tabItem(
tabName = "planner",
h4("Build out your training session. Choose a drill, select the duration, and how many repetitions (if more than 1) "),
fluidRow(box(
title = "Select number of drills for the training session below",
sliderInput(inputId = "drill_number",
label = "Number of drills", min = 1, max = 2, value = 1,step=1),
),
box(
title = "Select the players who are participating in the training session",
checkboxGroupInput("select_players", "Select Players for Training Session",
choices = c(1,2,3,4,5,6,7,8,9), selected = c(1,2,3,4,5),
inline = TRUE)
)),
tabBox( width = 12,
## 1st conditional Panel
tabPanel("ONE",
conditionalPanel(condition = "input.drill_number == 1",
# Drill 1
fluidRow(
box(width = 4,
selectInput("drill_1_select",
"Select Drill 1",
choices = c("Warm-Up Drill","Warm-Up Drill2"),
selected = "Warm-Up Drill"
), #end drill 1 select
),# end of box
box(width = 4,
sliderInput("drill_1_duration", "Select Duration of Drill 1",
min = 0, max = 60, value = 10, step = 1
),
) # end of box
# end of box
), #end first fluidrow
), # end first conditional Panel
# 2nd conditional Panel
conditionalPanel(condition = "input.drill_number == 2",
# Drill 2
fluidRow(
box(width = 4,
selectInput("drill_2_select",
"Select Drill 2",
choices = c("Warm-Up Drill","Rondo"),
selected = "Rondo"
), #end drill 2 select
),# end of box
box(width = 4,
sliderInput("drill_2_duration", "Select Duration of Drill 2",
min = 0, max = 60, value = 10, step = 1
),
) # end of box
# end of box
), #end 2nd fluidrow
)),
tabPanel("TWO",
fluidRow(width = 12,
tableOutput("drill1_preds")
)
),
tabPanel("THREE",
fluidRow(width = 12,
tableOutput("drill2_preds")
)
)
)
)
)
)
server <- function(input, output) {
## reactive for Drill 1 predictions
drill1_prediction_table <- reactive({
if(input$drill_number ==1){
df_1drill <- data.frame(Player_ID = as.factor(input$select_players), Drill = y <- rep(input$drill_1_select, length(input$select_players)), Duration = rep(input$drill_1_duration, length(input$select_players)))
# get predictions as vector
}
})
drill2_prediction_table <- reactive({
if(input$drill_number ==2){
df_1drill <- data.frame(Player_ID = as.factor(input$select_players), Drill = rep(input$drill_2_select, length(input$select_players)), Duration = rep(input$drill_2_duration, length(input$select_players)))
}
})
output$drill1_preds <- renderTable({drill1_prediction_table()}, striped = TRUE)
output$drill2_preds <- renderTable({drill2_prediction_table()}, striped = TRUE)
}
shinyApp(ui, server)