Skip to content

Instantly share code, notes, and snippets.

View jcheng5's full-sized avatar

Joe Cheng jcheng5

View GitHub Profile
@jcheng5
jcheng5 / gist:3989671
Created October 31, 2012 20:34
Fast worldwide CRAN mirror
options(repos=c(CRAN="http://cran.rstudio.com"))
library(shiny)
shinyServer(function(input, output) {
output$plot1 <- reactivePlot(function() {
plot(cars)
})
})
@jcheng5
jcheng5 / server.R
Created November 9, 2012 08:02
Reactive time example
shinyServer(function(input, output) {
output$currentTime <- reactiveText(function() {
# Forces invalidation in 1000 milliseconds
invalidateLater(1000)
as.character(Sys.time())
})
randomData <- reactive(function() {
if (!input$pause)
@jcheng5
jcheng5 / server.R
Created November 10, 2012 08:13
Shiny file upload demo
shinyServer(function(input, output) {
output$filetable <- reactiveTable(function() {
if (is.null(input$files)) {
# User has not uploaded a file yet
return(NULL)
}
input$files
})
})
@jcheng5
jcheng5 / server.R
Created November 10, 2012 23:33
Adding raw HTML to Shiny apps
# Nothing to see here
shinyServer(function(input, output) {
})
# global.R
dists <- list(
normal = list(
label = "Normal",
func = rnorm,
inputs = tagList(
sliderInput("mean", "mean: ", min=0, max=400, value=0),
sliderInput("sd", "st. dev.: ", min=0.1, max=20, value=1, step=.1)
),
params = c("mean", "sd")
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
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
dataset <- reactive(function() {
input$submitButton
write.csv(isolate({
c(input$foo, input$bar)
}))
})
<script src="https://github.com/livereload/livereload-js/raw/master/dist/livereload.js?host=localhost"></script>