ui <- pageWithSidebar(
headerPanel("Student Grades"),
sidebarPanel(
htmlOutput("varselect", inline=TRUE),
selectInput("Student", "Select a Student:", choices=htmlOutput("varselect"),
multiple = TRUE)
),
mainPanel(
dataTableOutput("table")
)
)
server <- function(session,input, output) {
set.seed(123)
Student<-rep(c("John","Jan","Mike","Charlie","Lauren"),4)
Term<-rep(1:5,4)
Grade<-runif(20,70,100)
df<-data.frame(Student,Term,Grade)
Dataset <- reactive({
df
})
output$varselect <- renderUI({
})
observe({
if (identical(Dataset(), '') || identical(Dataset(), data.frame()))
return(NULL)
updateSelectInput(session, inputId="Student", label="Pick a Student:",
choices=unique(Dataset()$Student))
})
output$table <- renderDataTable({
if (is.null(input$Student) || length(input$Student)==0)
return(NULL)
Dataset()[input$Student,]
})
}
shinyApp(ui, server)
```