How to use factor variable with multiple levels into selectInput() for shiny in a flexdashboard

256 Views Asked by At

I am trying to incorporate shiny into my flexdashboard, and I am encountering challenges with generating plots to correspond to the multiple levels of a factored variable when I run the app. My goal is to create a tab on my dashboard where the user can select from a set of student groups to view that individual group's outcome plot.

Here is the code for my selectInput:

selectInput("groups",
            "Student Group:",
            choices = levels(df$group))

Here is the code for my plot:

renderPlotly({
  df %>%
    group_by(!!rlang::sym(input$groups)) %>%
    ggplot(aes(assessment, score)) +
    geom_col(fill = "blue",
             alpha = 0.7) +
  scale_x_discrete(limits = test_order) +
  scale_y_continuous(limits = c(0,10),
                     breaks = c(0 ,2, 4, 6, 8, 10)) +
   coord_flip() +
   geom_text(aes(assessment, score, label = score),
             nudge_y = -0.5,
             color = "white") +
   facet_wrap(~student_name)
 })

The group variable is my factored variable with five levels that I want to appear in the selectInput() sidebar tab with each of its levels available to select from. When I run the app, the input with the appropriate levels appears in the sidebar; however, an error is produced where the plot should appear with the following message: "Must group by variables found in .data. Column group 1 is not found."

Any assistance or input on how to render my app to successfully display the levels with the corresponding plot would be greatly appreciated.

0

There are 0 best solutions below