JohnCoene / cicerone

🏛️ Give tours of your Shiny apps
https://cicerone.john-coene.com
Other
187 stars 7 forks source link

Detect if cicerone is running or not #20

Open etiennebacher opened 3 years ago

etiennebacher commented 3 years ago

It would be nice to be able to detect whether cicerone is running or not (this was already mentioned in #4 but I create a separate issue for that). driver.js provides an API method for that (isActivated) but I couldn't implement that because:

Is it possible to do that?

cllghn commented 1 year ago

I am not sure if this issue has gained any traction; however, it would be very useful to have this feature. While working on a Shiny app, I was hoping to change some inputs on the Shiny server side while cicerone was running, but found no clear way to reset the values when cicerone was closed.

I ended up with something like this:

tags$script(
  HTML(
    "
     const observer = new MutationObserver(function(mutationList){
            mutationList.forEach(function(mutation) {
                   mutation.addedNodes.forEach(function(node) {
                          if(node.id == 'driver-popover-item') {
                                 document.getElementsByClassName('driver-close-btn')[0].onclick = function() {Shiny.setInputValue('close_cicerone', true, {priority: 'event'} )};
                                 if(document.getElementsByClassName('driver-next-btn')[0].textContent === 'Done') {
                                        document.getElementsByClassName('driver-next-btn')[0].onclick = function() {Shiny.setInputValue('close_cicerone', true, {priority: 'event'} )};
                                 }
                               }
                                 }); 
                          });
                   });
     observer.observe(document.querySelector('body'), { subtree: false, childList: true });                                                              
    "
    )
)

Which enabled me to notify Shiny when cicerone was closed and then reset the inputs as needed. It would be nice to make this a bit cleaner on cicerone.

etiennebacher commented 1 year ago

Hi, I'm doing a self-promotion here (because this repo seems a bit inactive): this is possible with conductor

The syntax of this package is very similar to cicerone (I basically copied a lot of code) so it should be easy to use.