Huidong Tian's Blog

Don't know? Google it!

Add An Export Module to Shiny-app for Highcharts Figure

Highcharts is the best JavaScript chart library, I feel. By default, there is an export button which can let you save the interactive figure to PNG, JPEG, PDF and SVG format, and one important point is, you can use it in your shiny app through R package rCharts. However, there are some limits in such a way, the default exporting engine is based http, so if your shiny-app’s portal is https, then you can’t use the exporting feature (It seems Highcharts has also a https based export engine). I have spent a lot of time to configure a Highcharts export server, it works internally, but not outside. I can’t figure out the problem, but I found another solution.

Generate Distinct Colors

When plot with R (or some other software), it doesn’t bother you a lot for choosing colors if you have only several data series. For example, if I want to create a figure for 5 data series, I can easily choose red, green, dark green, blue and black. But what if I need to create a figure having 100 data series? Of course, we can choose different shape or pattern, like dash line, circle, triage, etc. However, to me, I feel that make the figure messy, I prefer all series in same style, except their colors. I created a Shiny-app which can generate random distinct colors in a certain color plate, would like to share it with public.

A Shiny-app Serves as Shiny-server Load Balancer

The Shiny-app on open-source edition Shiny-server has only one concurrent, which means it can run only for one user at a time point. But it can host multiple Shiny-apps, which can run synchronously. So, if we create severl Shiny-apps with different names but same function, then we can let more users use our service at same time. But users don’t how to choose the Shiny-app with small user number. This post will show you how to create a Shiny-app to redirect user to the Shiny-app with lower load.

Automatically Scrape Flight Ticket Data Using R and Phantomjs

I used to scrape static web pages with the R package RCurl. It’s a great package! When it comes to dynamic web pages, RCurl comes to be difficult to set up (actually, I never get it works). Then I met Phantomjs. PhantomJS is a headless WebKit scriptable with a JavaScript API. It has fast and native support for various web standards: DOM handling, CSS selector, JSON, Canvas, and SVG. In this blog, I will show how you to scrape flight tickets data using Phantomjs, extract and filter the entries that meet some restriction, and then send the result to your email automatically.

Set Up Shiny-server on

RStudio supplies several servers for hosting user’s apps, e.g.,, Thanks a lot to RStudio who has contributed many excellent R libraries! I want to set my shiny-server on a virtual private server (VPS), because I have some other tasks and I feel a VPS is more stable than the PC under my desk.

Shiny-server System Performance Monitoring for Open Source Edition

If you have deployed your Shiny-app on internet, you may curious about: how many users are using my app? Is the server powerful enough for hosting the app? You can get answers through the Server monitoring feature if you are using the Professional edition of Shiny server. What if we are using the Open source edition? Officially, there is no such a feature, but we can create it ourselves using Linux shell commands.

Set Up Highcharts Export Server On Ubuntu Server 12.04: Step by Step

There are a lot of JavaScript libraries for generating elegant and interactive charts, such as d3.js, RGraph, Google Charts, etc. However, most of them have no feature that can let users save their charts as images, except Highcharts! The charts generated by Highcharts contain a export button, users can use it to save charts as images. The mechanism of exporting feature of Highcharts is: by clicking the exporting button, users send a request to Highcharts’s export server with chart data, then the export server convert chart data (SVG) into images, e.g. JPEG, PNG, PDF, through PhantomJS, and send the generated images back to clients. So, there is a security problem! Even though Highcharts said they will never gather any information send to their export server, users’ chart data still can be intercepted by third part organizations. That’s a common problem of http protocol! In this blog, I will show you how to set up your own local highchart-export server step by step, which can be further set up to be accessible outside under https protocol.

Shiny-server Open Source Edition: Solution for CPU Bound Apps

Shiny-server integrates the statistic power of R with web, convenients the statistical analysis through web. Users can do complecate statistical anlysis through their web browsers. However, most of statistical analysis of R are CPU bound computation, that means CPU utilization is high, perhaps at 100% for many seconds. This leads to the problem of thread blocking: if one user is doing some calculation, the other user must wait until that process finished! For example, if one calculation needs 10 seconds to finish, and 4 users are doing the same calculation at same time, one user may need 10 seconds to get the result, and the unlucky one may need to wait 40 seconds! That’s annoying, but the native character of statistical analysis and R (R is single-thread: it uses only one core of your CPU).

Encrypt user’s password with md5 for you Shiny-app

In a previous blog, I post a simple authentication method for Shiny-app, and received several comments mainly concerning that I should encrypt user password. I agree, user’s password can be intercepted when it was transferring. To secure users’ personal information, I think we should consider both server and client sides.