1

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")
Adam Ryan
  • 13
  • 3
  • Welcome to SO! Could you make your example [reproducible](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) by providing sample data, e.g. by means of `dput(df)` (rather than `str(df)`), so that the code can be copy-pasted and run as is to reproduce the issue – Aurèle Dec 29 '21 at 08:38
  • 1
    Hi Aurele, sorry, I am new to this, first question ever asked on SO, hopeully this is how you would like the data. This is just how far i've got so far, I wanted to check that a limited version of the survey would work before expeanding it and linking it to google sheets. – Adam Ryan Dec 29 '21 at 10:08
  • 1
    The issue is with `dependence` and `dependence_value`: they should be `NA` (specifically `NA_character_`), and not `"NA"` – Aurèle Dec 29 '21 at 10:20
  • Thanks for your help Aurèle. – Adam Ryan Dec 29 '21 at 22:24

1 Answers1

1

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.

Dharman
  • 30,962
  • 25
  • 85
  • 135