kaijagahm / ygdpDashboard

Interactive dashboard for YGDP survey data
3 stars 0 forks source link

Fragility of defaultSentence1 for new surveys #39

Closed kaijagahm closed 3 years ago

kaijagahm commented 3 years ago

Currently, I have a manually-defined character string defaultSentence1, which is the text of the starting sentence for both points and interpolation mode.

There are some points in the code where I tell the selectors to initialize with this sentence in the dropdown menu, which assumes that this sentence is included in the initial survey, which is currently survey 11.

If we add new surveys to the app and they do not include that sentence, this will likely fail, or it will do the Shiny thing where the selector defaults to the first value if the "selected" value is not found, which could have weird downstream effects.

Also be cautious: the means of selecting the default sentence differs slightly between points and interpolation mode, and it would be good to have a robust system that works for both of them.

I think the ideal goal is for this variable to be set based on the input data itself. Hmm. That has interesting implications for the fact that I seem to have to define defaultSentence1 in the dashboardFunctions.R script. Does that mean we'd also need to load the data into that script instead of into the app itself? I don't think that would be a problem, though it is a little odd that Shiny is build that way.

kaijagahm commented 3 years ago

Indeed, this ended up causing problems. Thinking I was improving the fragility problem, I had gone into dashboardFunctions.R and changed defaultSentence1 to names(snl[[1]])[1], instead of defining that sentence manually. This was successful in assigning the default sentence to the sentence that appeared first in snl.Rda, no matter the version of the data being used.

However, this created a new problem. I use the function getSentenceChoices(), defined in dashboardFunctions.R, to organize the sentence choices into groups by grammatical category. Since "contact relatives" is the first group that appears alphabetically, the sentence that ultimately appears alphabetically is no longer names(snl[[1]])[1] ("But those people won't any of them fight fair."). Instead, it's getSentenceChoices(snl[[1]])[[1]] %>% unlist() ("John seems like Mary offended him.")

So, when the app would load, you would first see "But those people won't any of them fight fair.", but then it would get reset to "John seems like Mary offended him." through one of the updateSelectizeInput commands caused by the sentencesReset button being "clicked" in the process of assembling the app. (For some reason, ignoreInit on that observer doesn't prevent this from happening). So the sentence selector would get reset to the now-first sentence, the John and Mary one.

I've fixed this by resetting defaultSentence1 to getSentenceChoices(snl[[1]])[[1]] %>% unlist(), at the bottom of dashboardFunctions (so that it could make use of the previously-defined getSentenceChoices function).

This seems to work now, and ideally it should continue to work even with new versions of snl.Rda with new surveys and new sentences, although it's possible that problems will arise.

New version should work as of 5d967f838317574f5f150a6e7c9b1737a7ef7b5a, on the surveyNames branch. Has been deployed to kaijagahm.shinyapps.io and will soon be deployed to ygdp.shinyapps.io too.