jdtrat / shinysurveys

Develop and deploy surveys in Shiny/R.
https://shinysurveys.jdtrat.com/
Other
95 stars 27 forks source link

Feat: Show a dependency if a question is one (or more) of multiple values #48

Open jdtrat opened 2 years ago

jdtrat commented 2 years ago

This is particularly relevant for extended input types (e.g., select inputs with multiple = TRUE; also see #43). Possible implementation allows for dependency_value column to have comma-separated values that get parsed internally. In showDependence() function, we could then change the == to be %in%:

https://github.com/jdtrat/shinysurveys/blob/1e4a5b08b7c63218bfd11654a96240c5d34538ed/R/utils_render-survey.R#L65

@mikmart and @jmbo1190 what do you think about this idea/implementation?

jbodart-argenx commented 2 years ago

sounds ok but not sure what would be a good case for this. any example in mind?

mikmart commented 2 years ago

My initial thought was it'd be nice to not have to parse anything and use a list-column for dependency_value instead. But making that backwards compatible would add complexity, and it wouldn't play well with defining surveys in external files (Excel etc.).

With parsing, there's a likely rare, but possibly very confusing, case where a string value meant as a single dependency happens to contain the multi-value delimiter.

And lastly, would any() be the correct predicate for checking multiple values? I suppose it's the only one that makes sense with single-valued questions, but for multiple values you might also want all() or more complex ways to combine answers.

I'd perhaps try to think about a more general approach to handling complex dependence relationships.

jdtrat commented 2 years ago

All great points, @mikmart! I didn't think about the delimiter complexity but perhaps that could be a user-defined separation depending on their storage format (e.g., 'csv' and 'tsv' files could both use a | delimiter). Either way, I think this definitely requires a general approach and will give it some more thought.

@jbodart-argenx I'll see if I can think up a reprex (should've posted one initially, sorry about that!). Maybe @monitoringhsd has one?

monitoringhsd commented 2 years ago

@jdtrat, I have tried to explain and provide an example for my current use case in #49, where the dependence variable should have up to three values of previous questions from input_id. Please let me know if more details are needed.