Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rendering questions based on the input #44

Open
maksymiuks opened this issue Nov 5, 2020 · 2 comments
Open

Rendering questions based on the input #44

maksymiuks opened this issue Nov 5, 2020 · 2 comments

Comments

@maksymiuks
Copy link

I try to render questions based on the initial input with a hand of renderUI function evoked within the server. However, I constantly fail. Do you have any guide on how should I do it?

@daattali
Copy link
Owner

daattali commented Nov 5, 2020

This feature isn't supported. I'm not actively working on this package, but we can leave this issue open because it is something I wanted to explore when I do get back to working on it.

@HBuenoo
Copy link

HBuenoo commented Feb 17, 2021

Hello,

I needed to do something like this work, so i managed to use a reactive object to create a list of questions that goes to shinyforms formUI and formServer functions:

Code:

reactive_questions <- reactive({
    ids <-  Use some mechanism to get some input and turn it into an unique ID # its a vector

-- In my case, i used a select Input with division formulas, so i wanted N numerators and D denominators:

division<- input[['formula']] %>% strsplit(split = "/") %>% unlist()

-- this was my "mechanism":

ids <- division %>%
  strsplits(splits = c("*", "+", "-"), fixed = TRUE) %>% # just a recursive function for strsplit, taking many splits.
  stringr::str_replace_all("[[:punct:]]", "") %>% # These lines were specific for my string management.
  Xmisc::strip() %>%
  tolower() %>%
  stringr::str_replace_all(" ", "_") %>%
  stringi::stri_trans_general("Latin-ASCII")


labels <- turn the IDs into labels # also a vector

# for each element in the vectors, I add a question in the forms:    
questions <- list()

for (i in 1:length(ids)) {
  questions[[length(questions) + 1]] <- list(
    id = sprintf("%s", ids[i]),
    type = "numeric",
    title = labels[i],
    mandatory = TRUE
  )
}
return(questions) # list with questions
  })

form <- reactive({
     formInfo <<- list(
      id = "my_form_ID",
      questions = reactive_questions(),
      name = "My form name",
      reset = TRUE
    )
    return(formInfo)
  })

  output$ui_my_form<-  renderUI({
    formUI(form())
  })

It migth not be optimal, but it worked. Hope I can inspire you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants