Reputation: 1
I am making a Shinysurvey for some government agency. I have a dummy questionary.
This are the questions dataframe head
question | option | input_type | input_id | dependence | dependence_value | required |
---|---|---|---|---|---|---|
Nombre completo del personal que captura. | Nombre Primer apellido Segundo apellido | text | nombre_personal | NA | NA | TRUE |
Cargo | De acuerdo al organigrama | text | cargo | NA | NA | TRUE |
Correo electrónico | En minúsculas | text | correo | NA | NA | TRUE |
Entidad federativa | BAJA CALIFORNIA | select | entidad | NA | NA | TRUE |
Entidad federativa | BAJA CALIFORNIA SUR | select | entidad | NA | NA | TRUE |
Entidad federativa | CAMPECHE | select | entidad | NA | NA | TRUE |
Tail
question | option | input_type | input_id | dependence | dependence_value | required |
---|---|---|---|---|---|---|
CODE | AAAAA055555 | select | code | entidad | ZACATECAS | TRUE |
CODE | AAAAA055556 | select | code | entidad | ZACATECAS | TRUE |
¿Cuenta con energía eléctrica? | Sí | y/n | luz | NA | NA | TRUE |
¿Cuenta con energía eléctrica? | No | y/n | luz | NA | NA | TRUE |
¿Cuenta con internet? | Sí | y/n | internet | NA | NA | TRUE |
¿Cuenta con internet? | No | y/n | internet | NA | NA | TRUE |
This is the code I'm using. And it works.
library(shiny)
library(shinysurveys)
df <- read.csv("cuestionario_previa.csv", encoding = "latin1")
ui <- fluidPage(
surveyOutput(df = df,
survey_title = "Servicios de Energia Electrica e Internet",
survey_description = "Cuestionario rápido para el diagnostico de los servicios de luz e internet)
)
server <- function(input, output, session) {
renderSurvey()
observeEvent(input$submit, {
showModal(modalDialog(
title = "Congrats, you completed your first shinysurvey!",
"You can customize what actions happen when a user finishes a survey using input$submit."
))
})
}
shinyApp(ui, server)
But, as you can see in the tail, I have a question called CODE which is a dependent one from the question "entidad".
i.e. If entidad == "COLIMA"
I want a subset of CODE for this state.
With my dataframe I get this warning: Warning message: The select input "code" contains a large number of options; consider using server-side selectize for massively improved performance. See the Details section of the ?selectizeInput help topic.
I tried the ideas from: Is there any other way to create dependent survey questionnaire using R Shiny?
but couldn´t make it work
Also, I tried adding the selectize to my server
server <- function(input, output, session) {
renderSurvey()
updateSelectizeInput(session, "clues")
observeEvent(input$submit, {
showModal(modalDialog(
title = "Congrats, you completed your first shinysurvey!",
"You can customize what actions happen when a user finishes a survey using input$submit."
))
})
}
Upvotes: 0
Views: 108
Reputation: 11
the use of updateSelectizeInput
seems to be wrong. It should be something like:
updateSelectizeInput(session, 'id', choices = options, selected = character(0), server = TRUE)
where session is the session refering object, options is an character var with the full list of options to show, selected can be character(0) to show no default option or char string, and server = TRUE, that enables server side selectize.
I dont know how works the shinysurvey package, but you could develop the survey from scratch using nav_panel_hidden and working out the logic observing the answers.
Upvotes: 0