Skip to content

Instantly share code, notes, and snippets.

View aagarw30's full-sized avatar

Abhinav Agrawal aagarw30

View GitHub Profile
@aagarw30
aagarw30 / server.r
Created January 18, 2016 14:55
R Shiny - Download plot demo
library(shiny)
shinyServer(function(input,output)({
# x contains all the observations of the x variable selected by the user. X is a reactive function
x <- reactive({
iris[,as.numeric(input$var1)]
})
# x contains all the observations of the y variable selected by the user. Y is a reactive function
y <- reactive({
iris[,as.numeric(input$var2)]
@aagarw30
aagarw30 / server.r
Last active March 10, 2018 14:00
R Shiny and leaflet - Mapping the quakes dataset - demo app with leaflet methods and features - addCircles & addCirclemarkers
library(shiny)
library(leaflet)
shinyServer(function(input, output, session){
output$mymap <- renderLeaflet({
# Classifying the type of earthquake based on magnitude
quakes$type = ifelse((quakes$mag >= 4 & quakes$mag <= 4.9), "Light [4-4.9]",
ifelse((quakes$mag >= 5 & quakes$mag <= 5.9), "Moderate [5-5.9]",
ifelse((quakes$mag >= 6 & quakes$mag <= 6.9), "Strong [6-6.9]",
ifelse((quakes$mag >= 7 & quakes$mag <= 7.9), "Major [7-7.9]", "Great"
))))
library(shiny)
library(data.table)
# use the below options code if you wish to increase the file input limit,
# in this example file input limit is increased from 5MB to 9MB
options(shiny.maxRequestSize = 700*1024^2)
shinyServer(function(input,output){
# This reactive function will take the inputs from UI.R and use them for read.table() to read the data from the file. It returns the dataset in the form of a dataframe.
# file$datapath -> gives the path of the file
@aagarw30
aagarw30 / server.r
Created February 7, 2016 14:52
Example of R Shiny and googlevis package
library(shiny)
library(googleVis)
shinyServer(function(input, output, session){
output$bubble <- renderGvis({
@aagarw30
aagarw30 / server.r
Last active January 5, 2022 17:55
R Shiny Download GGPLOT demo
library(shiny)
library(ggplot2)
shinyServer(function(input,output)({
# x contains all the observations of the x variable selected by the user. X is a reactive function
x <- reactive({
iris[,as.numeric(input$var1)]
})
# x contains all the observations of the y variable selected by the user. Y is a reactive function
y <- reactive({
iris[,as.numeric(input$var2)]
@aagarw30
aagarw30 / server.r
Created February 18, 2016 18:59
Demo updateSelectInput in R Shiny
library(shiny)
shinyServer(function(input, output, session){
observe(
{input$Year
# Update based on the year change event
updateSelectInput(session, "Month", "Month", choices = data$Month[data$Year==input$Year])
}
)
@aagarw30
aagarw30 / server.r
Created March 13, 2016 08:19
R Shiny Demo - how to embed pdf into shiny app
library(shiny)
shinyServer(function(input, output,session){
})
@aagarw30
aagarw30 / server.r
Last active April 29, 2016 13:58
Create a frequency distribution
library(shiny)
shinyServer(function(input, output) {
# Split the elements input from the user
v <- reactive({
as.numeric(unlist(strsplit(input$vec1,",")))
})
# Print a message just before printing the vector values
@aagarw30
aagarw30 / DESCRIPTION
Last active July 28, 2021 13:12
Multiple action buttons in R Shiny
Title: Multiple Action Button Demo - An attempt to button event based navigation/actions. Powered by R, Shiny and Rstudio.
License: GPL-3
Author: Abhinav Agrawal
DisplayMode: Showcase
Tags: action button, R, R Shiny
Type: Shiny
@aagarw30
aagarw30 / DESCRIPTION
Last active May 12, 2016 18:41
Multiple action buttons - example 2
Title: Multiple Action Button Demo - Example # 2
Description: An attempt to button event based navigation/actions. Powered by R, Shiny and Rstudio.
License: GPL-3
Author: Abhinav Agrawal
DisplayMode: Showcase
Tags: action button, R, R Shiny
Type: Shiny