Blog posts on Data Science, Machine Learning, Data Mining, Artificial Intelligence, Spark Machine Learning

Thursday, March 20, 2014

Build Web applications using Shiny R

Ever since I’ve started working on R , I always wondered how I can present
the results of my statistical models as web applications. After doing some
research over the internet I’ve come across – ShinyR – a new package
from RStudio which can be used to develop interactive web applications with R.
Before going into how to build web apps using R, let me give you some overview
about ShinyR.

Features:
  • No JavaScript/HTML knowledge required. 
  • Can build interactive web applications which can load the data dynamically.
  • Pre-Built output widgets for displaying plots, tables interactively are available.
  • Works in any R environment.
  • Shiny Apps can be hosted locally/on self-hosted Shiny Server/Rstudio-hosted                              Shiny Server – in today’s post we will see hosting locally.

 Building a shiny App


Shiny application have two components: a user-interface definition and server script,
 and any additional data, scripts, or other resources required to support the
application.
UI script (ui.R): In this script we define the UI layout of the webpage. We can make
 use of inbuilt UI controls/widgets for displaying output and for creating UI layout..
Server Script (server.R): In this script, the actual business logic/ code for statistical
models, plotting the output is defined. It accepts inputs  from UI layer and compute
outputs send back the response to the UI layer. The basic task of a Shiny server
script is to define the relationship between inputs and outputs.

Understanding UI.R script:

library(shiny) #load shiny package
ds = read.csv("inputdata.csv") #load data
x = names(ds) # Define UI for application that plots distributions
shinyUI(pageWithSidebar(
# Application title
headerPanel("Demo Shiny Application"),
#sidebar panel to the left side of the page for input controls, slider & dropdown
sidebarPanel(
sliderInput('Year', 'Year', min=2010, max=2012,
value=min(2010,2012), step=1, round=0),
selectInput('select', 'Select Criteria', c(x[3],x[9],x[10],x[11],x[12],x[26]))
),
#main panel for displaying outputs, Histograms, summary
mainPanel(
plotOutput('plot'),
verbatimTextOutput("summary")
 ) ))




Notice in particular, in the above code sidebarPanel and mainPanel functions
 are called with two arguments - corresponding to the two inputs and
 two outputs displayed.

In the above image we can see the layout which contains a slider with year range,
where based on the year selection the dataset will be taken into consideration.
Dropdownlist containing varaibles, placeholder to display the graphs, table to
display the summaries of the models.

Understanding Server.R


In the above script, we can observe that all the logic for the exploratory analysis is
written in server.R script. It contains a main function called ShinyServer() 
wherein we can write reactive functions,reactive plots, outputs. The outputs
 are send back to the UI layer.
In the above code, I have written logic which contains data fetching, 
modification, setting the dataset based on the year selected in the 
slider (reactive function), displaying histogram based on the selection 
on slider and dropdownlist,writing summary to a table.

Deploying the application:

Once we are done with the application, next step is to deploy the application. 
Using Shiny, we have two different options to move the application to Production.
  • ** Create a local- self-hosted Shiny Server on Linux platform, here.
  • ** Host on the R-Studio's Shiny server, explained here
Deploying locally:

As mentioned in the beginning of the post, in order to deploy locally, we make
use of GIST. The steps are quite simple:
  • ** Upload the Server.R & UI.R files to the Gist.Github.com website.
  • ** Uploading the files gives you an ID - in my case - I got "8942533"
  • ** After finishing upload, open R and run the below code:
               library('shiny')
               shiny::runGist('8942533')
  • The model will be shown as web application will be displayed
 the browser with inputs for selection & outputs to display.


16 comments:

  1. Thank you for the auspicious write up. It in reality was once a leisure account it.Excellent items from you, man. I have be mindful your stuff prior to and you are simply extremely great. I really like what you have got here, certainly like what you are stating and the best way during which you say it. You’re making it enjoyable and you continue to care for to stay it sensible. I can’t wait to read far more from you. That is really a terrific web site.
    Custom essay writing service

    ReplyDelete
  2. Before I started working as a web developer for Dissertation Writing Service, I enrolled in various courses and enabled myself to excel in my organization. Working hard is a simple thing that can made you succeed.

    ReplyDelete
  3. IT is ruling the world, I’m a professional dissertation proposal writer and I have students coming for help in their dissertation writings all the time. Most of the time I have students of computer science and information technology to write their reports almost 80% of the crowd is of computer studies. I think other fields are obsoleting gradually. Anyways, I liked your blog, I’ll recommend to my students.

    ReplyDelete
  4. Hey everyone, I am Oliver & I am a college student. I am here to find some social science assignment help online and I think here are many professional academic writers available to help me out.

    ReplyDelete
  5. C++ web application development Modern C++ has a web GUI library called Wt. With widgets, you can create highly interactive online user interfaces without writing a single word of JavaScript. You can concentrate on functionality because Wt takes care of all request processing and page rendering for you.

    ReplyDelete
  6. I remember during covid I have nothing to do because I offer Dubai city tour deals before that. I started learning web development and now I am a professional in this field.

    ReplyDelete
  7. When I start working as a web developer for UK law essay writers, I enrolled in various courses and enabled myself to excel in my organization. Working hard is a simple thing that can made you succeed.


    UK law essay writers

    ReplyDelete
  8. Shiny R is a powerful tool that enables developers to build interactive web applications using the R programming language. It provides an easy-to-use interface for developers to create dynamic and interactive web applications without having to write complex code. With Shiny R, developers can quickly create data-driven web applications with minimal effort. The application can be used for a wide range of tasks such as data visualization, machine learning, data analysis, and more. With Shiny R, developers can easily develop robust and feature-rich web applications in no time. Most students are drawn to these types of articles and information, but they are unable to prepare for their exams, If you have been struggling with your exams and want assistance, pay to do my exam for me is dedicated to helping students get higher grades on their examinations by providing them with the best available resources, including quality academic services.

    ReplyDelete
  9. This blog post provides a comprehensive guide to harnessing the power of Shiny R for creating interactive web applications. It's a valuable resource for anyone interested in exploring this innovative approach to data visualization and user-friendly interfaces. If you're in need services of help write my assignment, look no further. British Assignments Help offers reliable and professional services to help write your assignment. Trust them to deliver high-quality solutions tailored to your specific requirements.

    ReplyDelete
  10. When it comes to building web apps, investing in professional help is crucial. pay for assignment services ensures that you receive top-notch expertise and timely delivery, allowing you to focus on other aspects of your project. Don't hesitate to seek assistance from reliable providers who can bring your web app vision to life. Remember, investing in quality support leads to efficient and successful outcomes.



    ReplyDelete
  11. One of the most significant monthly purchases for most people is food. POS Software For Grocery in Pakistan have decided to open several other locations. Opening numerous locations may seem exciting, but managing them effectively requires a powerful management system that keeps you informed of everything that happens across all of your grocery store's locations. Using a Point of Sale (POS) system's sophisticated features, you can effectively manage your expanding grocery business.

    ReplyDelete
  12. Shiny R is an incredible tool for building dynamic and interactive web applications effortlessly. Its user-friendly interface and seamless integration with R make it an invaluable asset for data visualization and analysis. With Shiny R, creating engaging and responsive web applications has never been more intuitive, making it a game-changer for data scientists and developers alike. Most students are drawn to these types of articles and information, but they are unable to prepare for their exams, If you have been struggling with your exams and want assistance, students can do my class - do my online class and get higher grades on their examinations by providing them with the best available resources, including quality academic services.

    ReplyDelete
  13. Its user-friendly interface and seamless integration with R make it an invaluable asset for data visualization and analysis. Most students are drawn to these types of articles and information, but they are unable to prepare for their exams, If you have been struggling with your exams and want assistance, students can do my class - help with my online class and get higher grades on their examinations by providing them with the best available resources, including quality academic services.

    ReplyDelete
  14. The complexity of data structures within Microsoft 365, including emails, documents, and collaboration sites, can complicate the migration and backup process. https://www.exchangesavvy.com/

    ReplyDelete
  15. Networking and collaboration are valuable CMA certification benefits that foster knowledge sharing and best practice exchange.

    ReplyDelete
  16. Accounting services for small business are essential for managing finances, ensuring compliance, and supporting growth. These services typically include bookkeeping, tax preparation, payroll management, financial reporting, and budgeting. By maintaining accurate records of transactions, businesses can better track cash flow, monitor expenses, and make informed decisions. Accounting professionals also help with tax filings, ensuring that businesses comply with local and federal regulations, which can save money and avoid penalties.

    Additionally, they assist with payroll, ensuring employees are paid accurately and on time. Outsourcing accounting services can be cost-effective for small businesses, freeing up time to focus on core operations while maintaining financial health and planning for the future. Reliable accounting support is a key factor in long-term business success.

    ReplyDelete