Skip to content

Instantly share code, notes, and snippets.

View jcheng5's full-sized avatar

Joe Cheng jcheng5

View GitHub Profile
@jcheng5
jcheng5 / global.R
Last active November 30, 2022 02:01 — forked from dgrapov/global.R
#initialize
library(datasets)
library(ggplot2)
#helper function (convert vector to named list)
namel<-function (vec){
tmp<-as.list(vec)
names(tmp)<-as.character(unlist(vec))
tmp
}
@jcheng5
jcheng5 / Global.R
Last active December 16, 2015 09:58 — forked from OliverBears/Global.R
library(chron)
library(shiny)
energy1=c(76.1,77,78.1,78.2,78.8,79.7,79.9,81.1,81.2,81.8,82.8,83.5)
cost1=c(7.1,7,7.1,7.2,7.8,7.7,7.9,8.1,8.2,8.8,8.8,8.5)
time1=c(20130301,20130401,20130501,20130601,20130701,20130801,20130901,20131001,20131101,20131201,20140101,20140201)
time1=as.Date(as.character(time1),format="%Y%m%d")
shinymonth=data.frame(time=time1,energy=energy1,cost=cost1)
#StrategicPestTechnologies: Functions
#~~~~~~~~~~~Calc trap info~~~~~~~~~~~~
trap.info.func<-function(file){
#Take file
#Return: traps, n.traps, ylims, xlims, total.area
traps<-read.table(file, header=FALSE)
colnames(traps)<-c("ID","X","Y")
n.traps<-dim(traps)[1]
@jcheng5
jcheng5 / global.R
Last active December 20, 2021 14:32 — forked from dempseydata/global.R
###############################################
##
## Attempt no 2 at building a shiny web app
## for AB Testing use - using global.R
##
## global.R - loading and defining variables for the global environment
##
###############################################
# Pallette used in some charts as a general indicator color for better or worse that the control group
@jcheng5
jcheng5 / server.R
Last active December 10, 2015 21:29 — forked from gdepalma/server.R
library(shiny)
shinyServer(function(input, output) {
output$intense <- reactivePrint(function() {
if(input$panel==2){
Sys.sleep(10)
return('Finished')
}else({return(NULL)})
})
<script src="https://github.com/livereload/livereload-js/raw/master/dist/livereload.js?host=localhost"></script>
@jcheng5
jcheng5 / server.r
Last active December 10, 2015 13:18
# Some pre-computed stuff in R. In this example, just assign values to a var
# data_sets <- c("mtcars", "morley", "rock")
data_sets <- c("mymtcars","mtcars", "morley", "rock")
mymtcars <- mtcars[,1:4]
shinyServer(function(input, output) {
mymtcars <- mymtcars
library(shiny)
shinyServer(function(input, output) {
re <- reactive(function(){
cat("re called\n",file=stderr())
input$n
})
output$ntext <- reactiveText(function() {
cat("output$ntext called\n",file=stderr())
@jcheng5
jcheng5 / server.r
Created October 29, 2012 06:21 — forked from wch/server.r
Experiments with shiny and ggplot2
library(shiny)
library(datasets)
library(ggplot2)
tg <- ToothGrowth
tg$dose <- factor(tg$dose)
# Define server logic
shinyServer(function(input, output) {