I have an rshiny app and I'd like to add a multi-paged survey using shinysurveys, but I'd only like that survey to appear when a "Take survey" button is clicked. I'm also hoping for it to be contained in a modal dialog.
I almost have this working, but the "pages" all get condensed into one. Any suggestions?
library(shiny)
library(shinysurveys)
survey <- data.frame(
question = c("Question 1", "Question 2"),
option = c("Answer 1", "Answer 2"),
input_type = c("text", "text"),
input_id = c("answer_1", "answer_2"),
dependence = c(NA,NA),
dependence_value = c(NA,NA),
required =c(F, F),
page = c(1,2)
)
ui <- fluidPage(
div(actionButton("clickforsurvey", "Take Survey")),
br()
)
server <- function(input, output, session) {
observeEvent(input$clickforsurvey, {
showModal(modalDialog(
shinysurveys::surveyOutput(
survey, survey_title = "Analyst Survey"
)))
renderSurvey(survey)
})
}
shinyApp(ui, server)