actionButton availability requirement

Hello everyone,

This is my first shinyapps and I am still a very early learner !

I am releasing an online survey on and use a package called "idefix" to develop it. It's a quite recent but very well theoritically designed package that is of particular interest for my PhD research project. Here is an image of what the survey and UI looks like.

The idefix package uses statistical techniques to best chose the last 4 questions (on 12) of the survey. But the downside is that the last 4 questions are longer to display on the UI, and that might even be longer on a server. And while the algorithm is choosing the best "choice set" (or options) to display to the respondant, the "Ok" button is still available and clickable!!! And if the respondant clicks on it, it jumps a question, with no answer gathered. Moreover, even during the 8 first questions (that are displayed instantly), the "Ok" button is also clickable if the respondant did not choose an answer!

So, I want to block the button from being clickable unless a selection between the 3 options is made.
I read about the req() function. Do you think it is the best way I have to "force" a selection between A, B and C, before the actionButton becomes clickable please? Or do you have any other suggestion?

Thanks for reading me :slight_smile:

req() is for skipping reactive's if the requisites are not available. Its probably not what you need which sounds more like something shinyjs could easily solve.

Could you make a small reprex ?

1 Like

Indeed shinyjs looks particularly interesting! Thanks a lot @nirgrahamuk.

Here is a small reprex that should run smoothly. It doesn't contain the slow creation of the last 4 questions as it requires an adapative set to be created, and for the sake of simplicity I did not do so, but the core of the app is created through this piece of code.

if(!require(tidyverse)) install.packages("tidyverse", repos = "")
if(!require(idefix)) install.packages("idefix", repos = "")
if(!require(shinyjs)) install.packages("shinyjs", repos = "")


n.sets <- 8
alternatives <- c("Alternative A", "Alternative B")
p.mean <- c(0,0,0)
p.var <- diag(length(p.mean))
levels <- c(3,3,3)
cand <- example_design
attributes <- c("time", "price", "comfort")
lvls <- list(c("2h", "5h", "10h"), c("15$", "8$", "1$"), c("Low", "Med", "High"))
itext <- c("Welcome to this reprex survey")
btext <- c("Please choose the alternative you prefer")
etext <- c("Thank you for taking the survey! Don't hesitate to share it with your friends and families, as it would be infinitely helpful for us.")

SurveyApp(des = example_design, 
 = n.sets, 
          alts = alternatives, 
          atts = attributes,
          lvl.names = lvls,
          coding = c("D", "D", "D"),
          buttons.text = btext,
          intro.text = itext,
          end.text = etext,
          prior.mean = p.mean,
          prior.covar = p.var,
          cand.set = cand,
          n.draws = 100

I thought that perhaps idefix generated sets of questions that you presented in your own shiny app , or else that it might have provided a module in your shiny app, but it seems to provide a complete shiny app. So the internals aren't directly manipulatable to you ( Though one could make alterations to the code and create their own 'version' of idefix, I think its slightly too big a task to be done on the forum) Therefore I think the standard way to proceed would be to raise an issue with the package author, and ask them consider making alterations to their package to support your needs.
Issues · traets/idefix (

Yes indeed, the package creates an app around the data input that you provide.

I already extracted the 'ui' and 'server' parts of the code as it's for now the only possible way to upload the app online through an app.R. And the aim is indeed to create my own version of the app.
Moreover I also contacted one of the author of the package today to see if there is any chance he could help me in implementing some features.

In any case, thank you for the hint on shinyjs, I will try to use it!!

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.