A little trick for debugging Shiny

February 3, 2019
By

(This article was first published on (en) The R Task Force, and kindly contributed to R-bloggers)

This is gonna be a short post about a little trick I’ve been using while developing Shiny Apps. (Spoiler: nothing revolutionary)

A browser anywhere, anytime

The first thing to do is to insert an action button, and a browser() in the observeEvent() watching this button. This is a standard approach: at any time, you just press this button, and you’re inside the Shiny Application — then, you can access the value of the reactiveValues and run the reactive elements, accessing the values they have at the moment you’ve pressed the button.

This approach works, and it’s robust. But here’s the issue: it’s kind of cumbersome to add/remove or comment/uncomment this button when you want to show, make screenshots, or simply remove this button to have a full view of the app.

So here’s a little trick that uses JavaScript to hide the button, and show it using the JavaScript console from your web browser:

# Add to your UI: 
actionButton("browser", "browser"),
tags$script("$('#browser').hide();")
# Add to your server 
observeEvent(input$browser,{
  browser()
})
# And to show the button in your app, go 
# to your web browser, open the JS console, 
# And type:
$('#browser').show();

As said, nothing revolutionary here, just sharing a little trick 😉

Ps: don’t forget to remove this button when you’ll send the app to be deployed to production.

The post A little trick for debugging Shiny appeared first on (en) The R Task Force.

To leave a comment for the author, please follow the link and comment on their blog: (en) The R Task Force.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Search R-bloggers

Sponsors

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)