Skip to content

Instantly share code, notes, and snippets.

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]])

@ijlyttle
ijlyttle / thoughts.md
Last active August 29, 2015 14:03
Shiny and rmarkdown

The goal is to be able to reproduce a website like "adv-r.had.co.nz", writing the content using rmd files, and to be able to embed (and serve) shiny content.

The way suggested by RStudio, in their rmarkdown documentation, is that the author provides an Rmd document to shiny-server, and it renders the entire document (including shiny) whenever the user demands it. In essence, shiny-server takes over the job that jekyll does for "adv-r.had.co.nz".

I have some questions about performance, caching strategies, and the like - but those will wait until I understand better the process.

There are formatting options; the author can create a template and tell shiny-server to use it when compiling. Looking again at the documentation, it seems that the tempate functions are defined in a package, then each Rmd file invokes the package and the template function in the output: bit of yaml. The tem

@ijlyttle
ijlyttle / howto.md
Created July 9, 2014 20:51
How to install R packages on Ubuntu

The challenge seems to be how to install R packages to the site library, rather than to the user's local library.

The R command .libPaths() is instructive here.

What I do is invoke R from the command line using sudo -i R. Apparently, this calls R as "root".

From R, calling .libPaths() confirms that my local directory is not there.

Then, I can use install_github or install.packages and it goes to the right place.

@ijlyttle
ijlyttle / example.Rmd
Created July 11, 2014 17:17
RMarkdown: reveal.js slide hierarchy
---
title: "Reveal test"
output:
revealjs_presentation:
pandoc_args: [ "--slide-level", "2" ]
---
## Slide 1
This is a slide
@ijlyttle
ijlyttle / vega_url_transitions.html
Last active August 29, 2015 14:03
Vega URL Transitions
<!DOCTYPE html>
<html>
<head>
<script src="https://trifacta.github.io/vega/lib/d3.v3.min.js"></script>
<script src="https://trifacta.github.io/vega/vega.js"></script>
</head>
<body>
<script type="text/javascript">
var url_spec = {
@ijlyttle
ijlyttle / shiny_embedded_widgets.Rmd
Created July 21, 2014 00:03
Reproducible example (perhaps not minimal) on shiny and rmarkdown
---
title: Nested Widgets
runtime: shiny
output: html_document
---
## Introduction
I seem to be able to something really cool using shiny, interactively, on my computer, but I cannot get it to work using shiny within an rmarkdown document run from shiny.
@ijlyttle
ijlyttle / file_update_reactive.R
Created July 25, 2014 17:39
idea to keep status on if data are ready in shiny
library(shiny)
shinyApp(
ui = wellPanel(
actionButton(
"file",
label = "file upload"
),
actionButton(
@ijlyttle
ijlyttle / sessionInfo.txt
Last active August 29, 2015 14:04
Issues with ggvis, shiny, and rmarkdown
> sessionInfo()
R version 3.1.0 (2014-04-10)
Platform: x86_64-apple-darwin13.1.0 (64-bit)
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base