Skip to content

Instantly share code, notes, and snippets.

View aagarw30's full-sized avatar

Abhinav Agrawal aagarw30

View GitHub Profile
@aagarw30
aagarw30 / Rplotlytutorial.r
Last active May 14, 2022 01:07
R Plotly Tutorial - Code Snippets
#### Brief introduction to R Plotly package ####
# The plotly package in R is an interface to open source Javascript charting library plotly.js
# Plots can be created online in the plotly web GUI or offline using the plotly package
# Interactive plots that can be easily shared online using the plotly API/account
# Plotly plots can embed into R Markdown, R Shiny
# Tool tip feature and other controls
# ggplot2 graphs can be easily converted to interactive plotly objects using ggplotly() function
# Package documentation
# https://cran.r-project.org/web/packages/plotly/plotly.pdf
@aagarw30
aagarw30 / server.r
Last active January 5, 2018 07:46
Save the plotly object to local system
library(shiny)
library(plotly)
library(ggplot2)
shinyServer(function(input,output)({
## Below plotting using plotly
output$plotlyplot <- renderPlotly({
p = plot_ly(data = iris, y=~Sepal.Length, type = "scatter")
# Using the export function to save the plot after the click of action button
@aagarw30
aagarw30 / server.r
Created November 28, 2017 18:57
Download plot
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 / DESCRIPTION
Last active August 8, 2017 04:26
Plotly, Dygraphs and R Shiny, save as png
Title: Experiment with plotly and dygraphs and save the output plot. Used export() function.
Description: Experiment with plotly and dygraphs and save the output plot. Used export() function to save the plot.
License: GPL-3
Author: Abhinav Agrawal
DisplayMode: Showcase
Tags: R, R Shiny
Type: Shiny
@aagarw30
aagarw30 / server.r
Created June 9, 2017 18:48
render Plot gist for you tube user query
library(shiny) # Load shiny package
data(iris) # Load the iris dataset
shinyServer(
function(input, output) {
output$text1 <- renderText({
@aagarw30
aagarw30 / DESCRIPTION
Last active September 18, 2020 17:47
Multiple Action buttons using reactiveValues() - an example
Title: reactiveValues() function
Description: With reactiveValues(), you can create your own reactive values. reactiveValues() Creates a list of objects that can be manipulated within a reactive context (within observer or observerEvent with dependency on changes in certain input or state of an object). reactiveValues() objects are not reactive themselves and do not re-execute themselves when input value changes unlike reactive objects. Powered by R, Shiny, and RStudio.
License: GPL-3
Author: Abhinav Agrawal
DisplayMode: Showcase
Tags: R, R Shiny,reactiveValues(), observeEvent()
Type: Shiny
@aagarw30
aagarw30 / server.r
Created May 30, 2017 06:43
Delete specific rows from data frame using reactiveValues() - example
library(shiny)
shinyServer((function(input, output) {
values <- reactiveValues(df = NULL)
observeEvent(input$file, {
values$df <- read.csv(input$file$datapath)
})
observeEvent(input$delete, {
values$df <- values$df[-input$rowno, ]
@aagarw30
aagarw30 / DESCRIPTION
Last active April 23, 2020 22:04
Simple counter using reactiveValues() in R Shiny - An example
Title: reactiveValues() function
Description: With reactiveValues(), you can create your own reactive values. reactiveValues() Creates a list of objects that can be manipulated within a reactive context (within observer or observerEvent with dependency on changes in certain input or state of an object). reactiveValues() objects are not reactive themselves and do not re-execute themselves when input value changes unlike reactive objects. Powered by R, Shiny, and RStudio.
License: GPL-3
Author: Abhinav Agrawal
DisplayMode: Showcase
Tags: R, R Shiny,reactiveValues(), observeEvent()
Type: Shiny
@aagarw30
aagarw30 / server.r
Last active January 24, 2018 19:30
multi-ggplot to PDF
library(shiny)
library(ggplot2)
library(gridExtra)
shinyServer(function(input,output)({
# downloadHandler contains 2 arguments as functions, namely filename, content
output$down <- downloadHandler(
filename = function() {
paste("multiplot.pdf")
@aagarw30
aagarw30 / server.r
Last active January 30, 2017 19:02
Hello Shiny App
library(shiny)
shinyServer(function(input, output,session){
})