Skip to content

Instantly share code, notes, and snippets.

View aagarw30's full-sized avatar

Abhinav Agrawal aagarw30

View GitHub Profile
@aagarw30
aagarw30 / App.R
Created April 7, 2022 03:34
Demo example for reactiveVal() with observeEvent() - Create dependency on actionButton - Subset data on click of actionButton and display in datatable
# Demo example for reactiveVal with observeEvent()
# Create dependency on a button to reflect user input changes to the rendered output
library(shiny) # for Shiny components
library(dplyr) # for piping
my = mtcars %>%
mutate(cyl = as.factor(cyl))
ui <- fluidPage(
h4("Demo of using reactiveVal() along with observeEvent() in R Shiny to subset data and display on click of action Button"),
@aagarw30
aagarw30 / action1.R
Last active April 5, 2022 19:05
Demo eventReactive() - subset data on click of button and display the resultant data
# Demo example for eventReactive()
# Create dependency on a button to reflect user input changes to the rendered output
# subset data on click of button and display the resultant data
# Load the required libraries
library(shiny) # for Shiny components
library(dplyr) # for piping and data manipulation
# For demo using the mtcars dataset
# convert the cylinder variable to factor type
@aagarw30
aagarw30 / ggcorrplot.R
Created March 14, 2022 18:57
R Tutorial - Visualization of correlation matrix in R using ggcorrplot package in R - ggcorrplot tutorial - ggplot2 extension
# Demonstration of ggcorrplot package
# Package created by Alboukadel Kassambara
# Reference link - https://cran.r-project.org/web/packages/ggcorrplot/ggcorrplot.pdf
# Load the required libraries
# install.packages("ggcorrplot")
library(ggcorrplot)
# mtcars dataset from base R used here for demonstration
@aagarw30
aagarw30 / App.R
Created October 8, 2020 04:14
USAArrests simple R Shiny App
# Load required packages
library(shiny)
library(ggplot2)
library(dplyr)
# Adding State column to the original dataset for easy data manipulation at a later stage
states = row.names(USArrests)
crimedata = USArrests %>%
mutate("State" = as.factor(states)) # convert State to a factor variable
@aagarw30
aagarw30 / App.R
Last active April 13, 2022 14:16
Choose plots and display using radio button
library(shiny)
ui <- fluidPage(
radioButtons(inputId = "plot_type" , label = "Select the plot", choices = c("scatter", "bar", "hist" )),
plotOutput("myplot")
)
server <- function(input, output, session) {
@aagarw30
aagarw30 / eventdata.R
Created April 1, 2020 08:00
Interactive data point selection with ggplotly/plotly charts
## Load required packages
library(plotly)
library(ggplot2)
library(shiny)
## Defining a key column in mtcars which will be used for event handling in event_data()
mtcars$key <- row.names(mtcars)
@aagarw30
aagarw30 / app.R
Last active January 9, 2020 14:03
Gist to disable Plotly Tool Bar that appears on the right top corner of Plotly plot - R Shiny App code sample
## How to disable the plotly tool bar from right top corner
## We will be using the pressure dataset for sake of demo
## Single file shiny app
## install the packages if not already
## Load the required libraries
library(shiny) # for shiny functions
@aagarw30
aagarw30 / server.r
Created May 12, 2018 12:49
fileinput - demo upload multiple files, perform operation and download the resultant dataset
library(shiny)
# 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 = 9*1024^2)
# options(shiny.trace=T)
shinyServer(function(input,output) {
## input$file is a data frame and contains the details around the name, size and temp location of the files uploaded
# this reactive output display the content of the input$file dataframe
output$filedf <- renderTable({
@aagarw30
aagarw30 / app.R
Created April 26, 2018 19:41
Update data value to NA based from a specific column based for the data points that are under the brush - Demo - brushedPoints() in R Shiny
# Load required packages
library(shiny)
library(ggplot2)
# UI Code begins here
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
## Add inputs widgets later
),
@aagarw30
aagarw30 / app.R
Last active March 25, 2018 19:23
R Leaflet - Animated marker - test
library(shiny)
library(leaflet)
library(dplyr)
# Create a small dataframe
visits = data.frame(City=c("Bangalore", "Delhi", "Chennai", "Bangalore"),
lat=c(12.972442, 28.644800, 13.067439, 12.972442),
lon=c(77.580643, 77.216721, 80.237617, 77.580643),
Year=c("2007", "2008", "2009", "2010"))
visits$Year = as.Date(visits$Year, format="%Y")