I'm creating a shiny app, and I want one of my tabs to be a 13 question quiz/game. However, I don't want all 13 questions displayed at once. I want to include an action button that when the user presses, the next question is displayed. Currently, both questions are displayed. Also, will I need to create separate action buttons for each question?
Problem 2: Questions 1-5 use the same plot. Questions 6-13 will use a different plot, and I will want both the question and the plot to be changed after question 5. I've provided 2 questions as an example.
In my UI script I have:
navbarPage(
"NEO Guess Who", position = "fixed-top",
tabPanel("Quiz",
fluidPage(
titlePanel(h1("Do you even know us?")),
sidebarLayout(
sidebarPanel(
radioButtons("q1", "Whose personality is plotted as the purple line?",
choices = list("Amy" = "Amy",
"Claire" = "Claire",
"Olivia" = "Olivia",
"Shae" = "Shae",
"Sharon" = "Sharon"),
selected = character(0)),
textOutput("q1text"),
actionButton("q1action", "Next", class = "btn-success"),
radioButtons("q2", "Whose personality is plotted as the blue line?",
choices = list("Amy" = "Amy",
"Claire" = "Claire",
"Olivia" = "Olivia",
"Shae" = "Shae",
"Sharon" = "Sharon"),
selected = character(0))),
mainPanel(
plotOutput("plot7"))
)))
)
within the server script, I have:
output$q1text <- renderText({
q1 <- switch (input$q1,
Amy = paste("Oops, the correct answer is Sharon"),
Claire = paste("Oops, the correct answer is Sharon"),
Olivia = paste("Oops, the correct answer is Sharon"),
Shae = paste("Oops, the correct answer is Sharon"),
Sharon = paste("Correct!"),
)
})
observeEvent(input$q1action, {
updateRadioButtons(session, "q1", choices = c("Amy", "Claire", "Olivia", "Shae", "Sharon"), selected = 0)
updateRadioButtons(session, "q2", choices = c("Amy", "Claire", "Olivia", "Shae", "Sharon"), selected = 0)
})
# both questions are still displayed
# no legend
output$plot7 <- renderPlot({
{neo_simple <- read.csv("neo_simple.csv", header = T, sep = ",")}
{neo_simple$domain <- factor(neo_simple$domain, levels = c("neuroticism", "extraversion", "openness", "agree", "conscient"))}
{neoColors <-
setNames( c('#a6cee3', '#b2df8a', '#fb9a99', '#fdbf6f', '#cab2d6'),
levels(neo_simple$id) )}
neo_simple %>%
ggplot(aes(x = domain, y=tscore, group = id, color = id)) +
geom_point(size = 1.75) +
scale_color_manual(values = neoColors) +
geom_line(size = 1.25) +
theme_bw() +
ggtitle("NEO Domain Scores") +
theme(plot.title = element_text(hjust = 0.5, size = 15)) +
theme(text = element_text(size=rel(4.5))) +
theme(legend.position = "none") +
theme(plot.caption = element_text(hjust = 0, size = 14))
})
Perhaps the 'slickR' package is a possible way: