I am trying to build an R shiny page that displays a plot based on inputs from the side panel. However, I would like the inputs on the sidebar to be reactive, meaning the choices in one input are based on the choices of prior inputs. For example, since Test 1 was not conducted in May, by selecting dates prior to may it would filter out Test 1 for the relevant input selection.
My guess is that each sidebar would filter the subsequent responses, but I'm not sure how to do this. Here is what I have so far, and I've included an example of what the dataframe I'm using looks like.
The ultimate goal is to be able to generate a reactive plot that demonstrates Test Results as a scatter or line plot, by comparing a single result over time or by comparing results to each other (ie., Result X on the X axis and result Y on the Y axis).
Dataframe
Name Test Date Result X Result Y Result Z
John Smith Test 1 2020-03-01 1.5 1.7 10
Sally Smith Test 2 2020-04-01 2.2 5.2 11
John Smith Test 3 2020-05-01 3.1 3.4 14
Sally Smith Test 2 2020-05-01 1.4 4.2 12
John Smith Test 3 2020-04-01 1.5 4.4 15
John Smith Test 1 2020-04-01 1.6 5.5 23
Sally Smith Test 1 2020-03-01 1.6 6.6 12
library(tidyverse)
library(shiny)
# Define UI for application
ui <- navbarPage("Title",
tabPanel("Title 1",
sidebarPanel(
h4("Title 1"),
selectInput("Name_Select", label = "Select Name", choices = df$Name),
dateRangeInput("dates", label = "Dates",
start = max(df$Date),
end = min(df$Date),
min = min(df$Date),
max = max(df$Date)),
selectInput("Test_Select", label = "Select Test", choices = df$Test),
selectInput("x_axis", label = "Variable 1", choices = select(df, Date, Result X:Result Z)),
selectInput("y_axis", label = "Variable 2", choices = select(df, Date, Result X:Result Z))),
mainPanel(plotOutput("Title1graph"))),
tabPanel("Title 2",
sidebarPanel(
h4("Title 2")))
)
# Define server logic
server <- function(input, output) {
output$Title1graph <- renderPlot({
plot(input$x_axis, input$y_axis)
})
}
# Run the application
shinyApp(ui = ui, server = server)