R Markdown Reports On Demand with MobileTrigger

[This article was first published on R – R-BAR, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Reports while on vacationR markdown is great for building reports that are easily re-rendered based on new or evolving data. But when you're on the road and can't run your R markdown report, what do you do? Usually, I'd say enjoy the fact that you're on the road or holiday and leave it for an official day at the office. But sometimes your boss, peers, or direct reports need the report and won't stop calling you. One way to deal with the need a report when out of office problem is to use the R MobileTrigger package.

The MobileTrigger package gives you the ability to request output from R models, scripts, and markdown reports via e-mail. Using the e-mail request framework, you can make a report request from your mobile device, web-mail service, or laptop and have the result delivered back to your mobile inbox. In this post, we'll focusing on setting up on demand R markdown reports with the MobileTrigger package.

Install and Setup the MobileTrigger package

The MobileTrigger package is available on CRAN and may being stalled with:

install.package("MobileTrigger")                      # CRAN
devtools::install_github("kenithgrey/MobileTrigger")  # GitHub

All the details you need to install and setup the MobileTrigger package may be found in my previous post MobileTrigger Setup: Run R Scripts, Models, Reports with Mobile Device. If you've already setup MobileTrigger and verified communications, just make sure you know the location of your “Trigger Path”. Lastly, if you're having trouble getting the MobileTrigger package working with gmail, Hotmail, or other webmail services, check out my other post “MailR SMTP Setup (Gmail, Outlook, Yahoo) | STARTTLS.

Make Your Demo R Markdown Report

To demonstrate the MobileTrigger workflow for reports, we are going use the default demo report generated by R-studio. To make a demo report, go to the R-studio menu bar and select File -> New File -> R markdown. When the R markdown dialogue window pops up, select “document” and enter a title and author. Mine looks something like this.

r markdown demo dialogue

For the purposes of our discussion, the generated R markdown file has two parts: the meta data at the top and the body below.

r markdown meta and body code

The MobileTrigger framework uses the meta data when listing out your available reports. So, keep your meta data clear, clean, and concise so you know what report you are running.

Need a cheat sheet for R markdown? [Click Here]

To close up this section, save your sample R markdown report as MobleTriggerTestReport.Rmd

Using your R Markdown Report with MobileTrigger:

For this section, I assume you have the MobileTrigger package installed and that you know the location of your “TriggerPath” on your desktop file system. If the MobileTrigger package is setup correctly, loading a basic report is very simple. Just copy the MobleTriggerTestReport.Rmd file you made in the previous section into the [TriggerPath]\report folder. On my system, the path looks something like this:

c:\Triggers\reports

In the screenshot below, you can see our sample R markdown file, along with a few other files in my reports folder.

example path to trigger folder

Awesome, now you're ready to verify that you can see your report on the list request via e-mail.

Verifying You Can Request the Report via an e-mail Request.

In this section, I assume you've already setup and verified communications with the MobileTrigger package as part of the installation process. In order to use MobileTrigger with your desktop, your e-mail client (thunderbird or outlook) needs to be running. If you have not completed the installation or verified communications, checkout my previous post MailR SMTP Setup (Gmail, Outlook, Yahoo) | STARTTLS. Also remember, that when you setup the mobileTrigger package you specified two important e-mail address:

  1. the e-mail address where requests are made
  2. the e-mail address where results are delivered

So, when you make your report list request below, make sure you send it from the correct e-mail address and that your desktop e-mail client is on.

List Reports

The first thing that we are going to do is see if our test report is listing properly. To do this, we are going send an e-mail from our mobile device to our desktop where the MobileTrigger package is installed. To list out reports available to MobileTrigger, the subject line of your e-mail read “Hey R – List Reports”. Press the send button on your mobile device and wait for R to process your request. In a moment or two, you should get an e-mail back listing out your reports. The requesting e-mail and report list out will look something like this:

MobileTriggers listing out reports

In the report list, you see that I have a few more reports than just our MobileTrigger demo report. Also, you should note that each report has a “Report ID” number associated with it in column 1. Lastly, notice that subsequent columns contain information from the meta data listed at the top of your R-markdown file. The graphic below illustrates how each column is populated from the R markdown meta data.

If you didn't get a list of reports back in your mobile mail box, check your MobileTrigger installation, your desktop e-mail client should be on, and make sure you are sending the request from the correct e-mail address.

Run Report

If everything went well in the last section, you should have received an e-mail back from R listing your reports with appropriate meta data. In this section, we are going to run our test report and get the result e-mailed back to us as an attachment. To run the report, create a new e-mail message on your mobile device. This time the subject line should read: “Hey R – Run Reports”. In the body of the e-mail, run the desired report by specifying the report ID with

UseReport: [target report ID]

An example is shown in the screenshots below.

MobileTriggers running reports

If everything goes well, you should get an e-mail and attachment back in your mobile device's mailbox within a few moments. Viewing the html-based R markdown report seems to happen by default in Outlook and Thunderbird. I can also load the report with no issue on my mobile device using the gmail app. However, if you are using gmail's webclient on your desktop, you may not see all the graphs in the report if you just click on the attachment. To overcome this issue on a laptop or desktop device, download and open the report locally in your browser.

Summary

In this short post, you learned how to request an on demand R markdown report using your mobile device and the MobileTrigger framework. In a nut shell:

  1. Get MobileTrigger installed (the hardest part).
  2. Make the report and save it to your MobileTrigger “reports” folder.
  3. Verify the new report is listed when making a list request from the appropriate e-mail address. Subject line should be “Hey R – List Reports”
  4. Run the desired report by sending an e-mail from your mobile with the subject line “Hey R – Run Reports” and specifying the report you want to run appropriately in the e-mail body.
  5. That’s it.

In future posts, we'll look at how to run models and launch scripts using a similar process.

Other Articles from r-bar.net


MobileTrigger Setup: Run R Scripts, Models, Reports with Mobile Device

MailR SMTP Setup (Gmail, Outlook, Yahoo) | STARTTLS
Running Remote R Scripts with Mobile Devices using E-mail Triggers
WooCommerce Image Gallery | Step by Step, Automate with R
XmR Chart | Step-by-Step Guide by Hand and with R
Windows Clipboard Access with R

The post R Markdown Reports On Demand with MobileTrigger appeared first on R-BAR.

To leave a comment for the author, please follow the link and comment on their blog: R – R-BAR.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

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)