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

Introduction 

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).

Pre-Requisites

Basic understanding of R and some background with statistics.

Installing R programming language

  1. Download and Install latest version of R Studio
  2. https://www.rstudio.com/products/rstudio/download/
  3. Download and Install latest version of R
  4. https://cran.r-project.org/bin/windows/base/
  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()
        {
            REngine.SetEnvironmentVariables();
            engine = REngine.GetInstance();
            engine.Initialize();
        }



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)
        {
            try
            {
                var engine = Startup.engine;
                var gp = new GraphPanel();
                engine.Install(gp);
                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();
                engine.Evaluate("hist(x)");
                engine.Evaluate("dev.off()");
                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.

References

1] https://www.r-project.org/about.html
2] http://www.tutorialspoint.com/r/

comments powered by Disqus