daattali / shinyjs

💡 Easily improve the user experience of your Shiny apps in seconds
https://deanattali.com/shinyjs
Other
734 stars 119 forks source link

Use shinyjs in the authorisation page of a shinymanager app #258

Closed pepijn-devries closed 1 year ago

pepijn-devries commented 1 year ago

Hi @daattali,

I'm using the shinymanager package, which allows me to check credentials before granting users to the main page. This is achieved by wrapping the ui object inside a call to secure_app. Putting a call to useShinyjs() inside the original ui will not affect the authorisation page, where the user will start. Consequently, the server is not able to call javascript functions using runjs, when on this page. It took me a while to figure out that if you want to achieve this, you will need to add the following argument to the secure_app function: ui <- secure_app(ui, head_auth = useShinyjs()).

Maybe this usage can be added to the following vignette, to help others that are struggling with the same issue?:

https://cran.r-project.org/web/packages/shinyjs/vignettes/shinyjs-usage.html

daattali commented 1 year ago

I'd be happy to accept a PR if you want to add a short section for this in the vignette.

daattali commented 1 year ago

I've been thinking about this for a little while and looked at some example usages of {shinymanager}. In my opinion, this is out of scope for shinyjs, and is much better suited to be documented by {shinymanager}.

The secured_app() function needs to make it clear that the page's UI is not executed before being authorized, and therefore any scripts there will not take effect. The documentation for the head_auth parameter is unclear, I myself read it and did not understand that javascript code can go in there. I'm sorry I asked you to submit a PR, but I do very strongly believe this type of documentation should be done in the other package. It would also help people in other contexts, not just with shinyjs.

pepijn-devries commented 1 year ago

Thank you for reflecting on this. After reading your comment I agree that this would be better suited in the shinymanager documentation. I will open an issue there with a reference to this issue...