Creating Graphs and business intelligent dash board in MVC web apps using RdotNet


In this article, I will be showing you, step-by-step, how to create a web-based Business Intelligence Dashboard using ASP.NET MVC and AngularJS  that uses R In this article we will be using temp data to do transformations on it that are then displayed on the dashboard. In the subsequent article, I will go on to show you how to use R visualization libraries to transform the real data into graphs that highlight the trends in the data and show some statistical measures to make the application more versatile.

Introduction to R

R is a programming language and software environment for statistical computing and graphics supported by the R Foundation for Statistical Computing. The R language is widely used among statisticians and data miners for developing statistical software and data analysis. Polls, surveys of data miners, and studies of scholarly literature databases show that R's popularity has increased substantially in recent years. (Taken from wikipedia).


Basic understanding of R and some background with statistics.

Installing R programming language

  1. Download and Install latest version of R Studio
  3. Download and Install latest version of R
  5. After installing both need to set path environment variable, Open System Configuration
  6. Click on Advanced System Settings
  7.        Click on Environment Variables
  8. Double Click on Path
  9. Click on new to add new path
  10. BY default path is C:\Program Files\R\R-3.2.3\bin\i386
    Please make sure to check path by going to R installation directory because version may be different
  11. Add this Path and click OK to save changes


Now Moving to MVC

 After that come to visual studio and create new MVC project

Add reference to Rdotnet from nuget


We need RdotNet, RDotNet.NativeLibrary and RDotNet.Graphics

After that we need to have to initialize REngine



We need to include reference to our post

using RDotNet;

And also call function from some  where that will be called only once application start
may be "startup.cs" or program.cs file

        private void configureEngine()
            engine = REngine.GetInstance();

After that we can use R power to get histogram or any other graph in just small piece of code

              public string TestGP(int company)
                var engine = Startup.engine;
                var gp = new GraphPanel();
                engine.Evaluate("x <- c(2.89, 9.93, 21.72, 19.98, 10.02, 9.8, 9.93, 21.72, 19.98, 10.02, 9.8)").AsNumeric();
                var bmp = Convert.ToBase64String(ImageToByte(gp.bmp));
                return bmp;
            catch (Exception exp)
                var messag = exp.Message;
                return messag;
A sample graph is given bellow

you could get as rich functionality as you want.



comments powered by Disqus