Skip to content

Instantly share code, notes, and snippets.

View xiaodaigh's full-sized avatar

evalparse xiaodaigh

View GitHub Profile
@xiaodaigh
xiaodaigh / testparse.r
Created September 30, 2013 06:29
Test parset shiny
#find top level expression
ancestor <- function(code.pd,id,ancestors_parent_id=0) {
this <- code.pd[code.pd$id == id,]
if(this$parent == ancestors_parent_id) return(this)
immediate_parent = code.pd[code.pd$id == this$parent,]
if(immediate_parent$parent == ancestors_parent_id)
return(immediate_parent)
return(ancestor(code.pd,immediate_parent$id,ancestors_parent_id))
}
@xiaodaigh
xiaodaigh / server.R
Last active December 24, 2015 08:49 — forked from tcash21/server.R
require(shiny)
require(rCharts)
inputChoices <- c("A", "B", "C", "D")
shinyServer(function(input, output, session){
input2Choices <- reactive({
inputChoices[-grep(input$input1, inputChoices)]
})
?showReactLog
options(shiny.reactlog=TRUE);
session$sendCustomMessage(type="jsCode",
list(code= paste("$('#",id,"').prop('disabled',true)"
,sep="")))
tags$head(tags$script(HTML('
Shiny.addCustomMessageHandler("jsCode",
@xiaodaigh
xiaodaigh / server.R
Created October 1, 2013 16:20
Shiny output doesn't run if no input?
library(shiny)
library(shinyIncubator)
options(shiny.reactlog=TRUE);
shinyServer(function(input, output,session) {
output$test <- renderPlot({
input$meh
print("wassup")
withProgress(session, min=1, max=15, {
@xiaodaigh
xiaodaigh / server.r
Created October 12, 2013 06:16
Shiny R - Re-initialise reactive values
library(shiny)
shinyServer(function(input,output){
reval <- reactiveValues(a= 1,b=2,dummy= rnorm(1))
observe({
if(input$hello == 0) return()
random.number <- rnorm(1)
reval$dummy <- random.number
b <- reval$b
data <- read.csv("c:/bb2.csv")
cor.data <- cor(data[sapply(data,typeof)=="double"],method="spearman")
dist <- function(y,x) {
if(is.null(dim(x))) {
sqrt((x[1] - y[1])^2 + (x[2] - y[2])^2)
} else {
sqrt((x[,1] - y[1])^2 + (x[,2] - y[2])^2)
}
@xiaodaigh
xiaodaigh / intro.r
Created January 22, 2014 12:26
Intro to R
# reading and writing files
# press ctrl+enter to send
iris
fix(iris)
write.csv(iris,"c:/temp/iris.csv")
iris2 = read.csv("c:/temp/iris.csv")
nrow(iris2)
# get help
@xiaodaigh
xiaodaigh / server.r
Last active February 2, 2016 18:07
R Shiny: An textInput that only gets invalidated upon losing focus or when enter is pressed shiny::runGist("7150112")
library(shiny)
shinyServer(function(input, output, session) {
# Partial example
output$meh <- renderPrint({
print("Press enter or focusout to update --- ")
print(input$myTextInput )
@xiaodaigh
xiaodaigh / README.md
Last active February 1, 2017 02:15
== actionButton styling == The Twitter Bootstrap allows for many class styles for buttons. http://getbootstrap.com/2.3.2/base-css.html#buttons Added support for these styles to the actionButton.
@xiaodaigh
xiaodaigh / how_to_use_split_into_columns.sas
Last active August 25, 2017 05:22
A SAS macro to split a dataset (.sas7bdat) into datasets where each resultant dataset contains exactly one column of the original data
data a;
do i = 1 to 10000;
b = i;
output;
end;
run;
%include "path/to/split_into_columns.sas";
libname outlib "path/to/output/dataset/";