I am trying to create a survey on shinysurveys. I have an excel file I am reading in and I believe all the columns and formatting are correct. The app launches but there are no questions appearing, just the title. Please help.
library(shiny)
library(shinysurveys)
library(readxl)
library(tidyverse)
df <- readxl::read_xlsx('questions.xlsx') %>%
group_by(question) %>%
nest() %>%
ungroup()
multiQuestions <- df %>%
mutate(page = c(
rep(1, 2),
rep(2, 2))
)
multiQuestions1 <- multiQuestions %>%
unnest(cols = data) %>% as.data.frame()
ui <- fluidPage(
surveyOutput(df = multiQuestions1,
survey_title = "the Big Crypto Personality Survey",
survey_description = "xxxxx",
theme = "#63B8FF"
)
)
server <- function(input, output, session) {
renderSurvey()
}
shinyApp(ui, server)
Data looks like this
structure(list(question = c("What do you hold?", "What do you hold?",
"What do you hold?", "What do you hold?", "What do you hold?",
"What do you hold?", "What do you hold?", "What do you hold?",
"What do you hold?", "What do you hold?", "What is your main holding?",
"What is your main holding?", "What is your main holding?", "What is your main holding?",
"What is your main holding?", "What is your main holding?", "What is your main holding?",
"What is your main holding?", "What is your main holding?", "What is your main holding?",
"What's your age ?", "Which best describes your gender?", "Which best describes your gender?",
"Which best describes your gender?", "Which best describes your gender?"
), option = c("BTC", "ETH", "BNB", "SOL", "ADA", "XRP", "LUNA",
"DOT", "AVAX", "DOGE", "BTC", "ETH", "BNB", "SOL", "ADA", "XRP",
"LUNA", "DOT", "AVAX", "DOGE", "25", "Female", "Male", "Prefer not to say",
"Prefer to self describe"), input_type = c("mc", "mc", "mc",
"mc", "mc", "mc", "mc", "mc", "mc", "mc", "mc", "mc", "mc", "mc",
"mc", "mc", "mc", "mc", "mc", "mc", "numeric", "select", "select",
"select", "select"), input_id = c("overall", "overall", "overall",
"overall", "overall", "overall", "overall", "overall", "overall",
"overall", "main", "main", "main", "main", "main", "main", "main",
"main", "main", "main", "age", "gender", "gender", "gender",
"gender"), dependence = c("NA", "NA", "NA", "NA", "NA", "NA",
"NA", "NA", "NA", "NA", "NA", "NA", "NA", "NA", "NA", "NA", "NA",
"NA", "NA", "NA", "NA", "NA", "NA", "NA", "NA"), dependence_value = c("NA",
"NA", "NA", "NA", "NA", "NA", "NA", "NA", "NA", "NA", "NA", "NA",
"NA", "NA", "NA", "NA", "NA", "NA", "NA", "NA", "NA", "NA", "NA",
"NA", "NA"), required = c(TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE), page = c(1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2,
2, 2, 2)), row.names = c(NA, -25L), class = "data.frame")
CodePudding user response:
As Auréle mentioned, the issue is that the missing values (NA
) are encoded as character strings ("NA"
). I don't have a lot of experience with the readxl package, but it looks as if you can define what missing values should be encoded as NAs upon reading the questions in (see the na
argument here). If that doesn't work, you can always use dplyr::mutate()
to set the dependence and depdence_value columns equal to NA as follows:
# This assumes there are no dependency questions.
# If there are, you can use `case_when()` to selectively
# ensure NAs are encoded correctly.
multiQuestions1 %>%
dplyr::mutate(
dependence = NA,
dependence_value = NA
)
Hope that helps! Also, I saw you might be looking to connect this survey with Google Sheets. Here's a blog post I wrote to walkthrough that process.