Skip to content

Instantly share code, notes, and snippets.

@reinholdsson
reinholdsson / ggvis-app.R
Last active May 21, 2019 13:10
R ggvis shiny app transition
library(ggvis)
library(shiny)
library(dplyr)
shinyApp(
shinyUI(fluidPage(
titlePanel("Example"),
sidebarLayout(
sidebarPanel(
sliderInput("maximum_supply",
@reinholdsson
reinholdsson / code.R
Last active January 6, 2023 12:08
dplyr, rlang, etc.
library(dplyr)
df <- nycflights13::flights
.a <- quote(sched_dep_time + dep_delay)
.b <- function() quote(sched_dep_time + dep_delay)
.c <- function(x) bquote(.(substitute(x)) + dep_delay)
.d <- function(x) {
x <- enquo(x)
expr(!!x + dep_delay)
@reinholdsson
reinholdsson / shellout.py
Created September 8, 2016 09:15 — forked from miku/shellout.py
shellout
def shellout(template, **kwargs):
"""
Takes a shell command template and executes it. The template must use
the new (2.6+) format mini language. `kwargs` must contain any defined
placeholder, only `output` is optional.
Raises RuntimeError on nonzero exit codes.
Simple template:
wc -l < {input} > {output}
@reinholdsson
reinholdsson / app.lua
Created December 1, 2015 22:19
lua lapis upload file service
local lapis = require("lapis")
local http = require("socket.http")
local app = lapis.Application()
is_file = function(input)
return type(input) == "table" and input.filename ~= "" and input.content ~= "", "Missing file"
end
app:match("/", function()
return "Image Service"
@reinholdsson
reinholdsson / server.R
Created October 2, 2015 14:26 — forked from jpd527/server.R
Drag n drop list Shiny JS
library(shiny)
shinyServer(function(input, output,session) {
output$list <- renderUI({
sortListInput("sortable",c(test1="one",test2="two"))
})
})
@reinholdsson
reinholdsson / online_google_auth.r
Created September 29, 2015 14:32 — forked from MarkEdmondson1234/online_google_auth.r
Google OAuth2 Authentication functions for an R Shiny app
## GUIDE TO AUTH2 Authentication in R Shiny (or other online apps)
##
## Mark Edmondson 2015-02-16 - @HoloMarkeD | http://markedmondson.me
##
## v 0.1
##
##
## Go to the Google API console and activate the APIs you need. https://code.google.com/apis/console/?pli=1
## Get your client ID, and client secret for use below, and put in the URL of your app in the redirect URIs
## e.g. I put in https://mark.shinyapps.io/ga-effect/ for the GA Effect app,
@reinholdsson
reinholdsson / code.R
Last active August 29, 2015 14:21
OLD: kolada with maps example (see swemaps package instead)
library(ggplot2)
library(rkolada)
library(stringr)
# Get coordinates/polygons data
prepare_map_data <- function(x) {
poly <- read.csv('https://db.tt/rexpDv4U') # see also 'https://db.tt/lNz7K3KD' for regions/lnkod
poly$municipality.id <- str_pad(poly$knkod, 4, 'left', '0')
res <- merge(poly, x, by = 'municipality.id')
res[order(res$order),] # it must be sorted by the 'order' column, or else the map fail!
@reinholdsson
reinholdsson / README.md
Last active August 29, 2015 14:07
Install PostgreSQL PL/R on Mac OS X

In terminal:

cd ~
curl "http://www.joeconway.com/plr/plr-8.3.0.15.tar.gz" -o "plr-8.3.0.15.tar.gz"
tar xzf plr-8.3.0.15.tar.gz 
cd plr
R_HOME="/Library/Frameworks/R.framework/Resources/" USE_PGXS=1 PG_CONFIG="/Applications/Postgres.app/Contents/Versions/9.3/bin/pg_config" make
R_HOME="/Library/Frameworks/R.framework/Resources/" USE_PGXS=1 PG_CONFIG="/Applications/Postgres.app/Contents/Versions/9.3/bin/pg_config" make install
'/Applications/Postgres.app/Contents/Versions/9.3/bin'/psql -p5432 test
@reinholdsson
reinholdsson / code.r
Last active August 29, 2015 14:03
R: (faster) single value dcast function
require(data.table)
single_val_dcast <- function(data, x, y, value, fill = NA) {
# x . .
# y
# .
# .
if (!is.data.table(data)) {
stop('Input data must be a data.table.')