Although, RMarkdown and R-Notebook provide an excellent tool for performing quick analysis and the ability to share the outcome as both web page and PDF document, they lack the ability to interactively change the parameters without a code change. They are designed for an efficient single use purpose. If the need is to modify the parameters that drive the analysis or visualisation, then Shinyapps is the answer.
In a previous article, an R-Notebook was created to demonstrate this with a technical analysis report of the AAPL (Apple Inc.) stock, and the visual also displayed overlays and add-ons of certain technical indicators. To change the stock, or the data range of the visual, or remove some technical indicators would require a change to the code and a repeat execution. This article shows how that R-Notebook code was changed to a Shinyapp with only a little extra effort.
The prerequisites for the Shinyapp were setup by following the excellent article by Dean Attali. This article will take you through A-to-Z of setting up your own R-Server and Shiny server environment. Of course, this is not necessary to write a Shinyapp, as Shiny is just another package of R-Studio. But, if you want to write Shinyapps and host them on some cloud provider than the cited article is necessary reading.
Converting the original R-Notebook code into that required by the Shinyapp was straight forward, the addition was the UI widget code. The technical analysis of a stock requires has three parts, viz., the stock symbol, the date range of interest, and the choice technical indicators. To make the Shinyapp interactive would require the data made available to the UI widgets before they are rendered. The implementation for this can at times render nginx to fail with a 502 error, a communication break upstream.
The screen capture above shows the final application running in a browser of the host, and served by the Ubuntu sever guest VM image.
- The Shinyapp is serviced by the end-of-day prices captured and saved in a MySQL table. As this data grows a more optimised solution must replace the current implementation.
- The technical indicators can be further enhanced by providing additional UI widgets to allow their parameters to be modified too.
- The charts can be of better clarity, but for this exercise the visualisation is fine.
- There are many technical measures that can be used, but we focused on those that we are acquainted with, and those that are most often found being used in the literature. The purpose was not to astound the readers with exotic technical measures, of which there ae plentiful.