Skip to content

Instantly share code, notes, and snippets.

@ijlyttle
ijlyttle / lubridate_dst.r
Created February 18, 2013 18:23
An illustration of the difference between a duration and a timespan
require("lubridate")
# in the USA, daylight-saving time begins for 2013 on 10 Mar.
dtm_start <- ymd("2013-03-10", tz="America/Chicago")
dtm_start
dtm_start + duration(1, "day")
dtm_start + days(1)
@ijlyttle
ijlyttle / gist:5166715
Created March 15, 2013 01:04
Rtools path
c:\Rtools\bin;c:\Rtools\gcc-4.6.3\bin;c:\Rtools\MinGW\bin
@ijlyttle
ijlyttle / plyr_lubridate_test.R
Created April 23, 2013 15:37
using ddply seems to wipe out the "Duration"
library(plyr)
library(lubridate)
n_intvl <- 48
dur_intvl <- dseconds(900)
intvl_15min <- data.frame(
start = ymd("2001-01-01", tz="America/Chicago") + seq(0, n_intvl-1)*dur_intvl,
dur = rep(dur_intvl, n_intvl)
)
@ijlyttle
ijlyttle / server.R
Last active December 14, 2020 14:20
demonstration of attempt to get `conditionalPanel` to work on a file-upload condition
library(shiny)
shinyServer(function(input, output) {
# Has a file been imported?
output$csv_import_ready <- reactive({
return(!is.null(input$csv_import_file))
})
# SOLUTION (2013-08-17)
@ijlyttle
ijlyttle / server.R
Created August 14, 2013 20:57
coding all elements by hand
library(shiny)
items <- c("seed")
shinyServer(function(input, output) {
add_item_a <- reactive({
# register button
n_click <- input$item_add_a_go
@ijlyttle
ijlyttle / server.R
Created August 14, 2013 20:58
closure to automate reactivity functions
library(shiny)
items <- c("seed")
shinyServer(function(input, output) {
cl_add_item <- function(name_value, name_button){
# function to add item
add_item <- reactive({
@ijlyttle
ijlyttle / server.R
Created August 14, 2013 20:59
function to automate repeated groups of UI elements
library(shiny)
items <- c("seed")
shinyServer(function(input, output) {
# closure to generate reactive function to add items
cl_add_item <- function(name_value, name_button){
# function to add item
library(dplyr)
mtcars_slim <- summarize(mtcars, mpg, cyl)
summary(mtcars_slim) # ok
str(mtcars_slim) # not ok
mtcars_slim # just weird
mtcars_slim[3, ] # even weirder
sessionInfo()
@ijlyttle
ijlyttle / server.R
Last active August 29, 2015 13:58
ggvis and shiny
library(shiny)
library(ggvis)
data(diamonds, package = "ggplot2")
shinyServer( function(input, output, session) {
hist_standard <- reactive({
    df_data <- 
      tbl(src_azure, "devicestate") %>%
      select(dtm = UTC_DateTime, ActiveCool, Temperature_C, Sum_Power_wh) %>%
      filter(DeviceID == input$device) %>%
      filter(UTC_DateTime > dtm_range[[1]] & UTC_DateTime < dtm_range[[2]]) %>%
      collect()

The line filter(UTC_DateTime &gt; dtm_range[[1]] &amp; UTC_DateTime &lt; dtm_range[[2]]) should work as filter(dtm &gt; dtm_range[[1]] &amp; dtm &lt; dtm_range[[2]])