Skip to content

Instantly share code, notes, and snippets.

@reinholdsson
reinholdsson / 01-load-packages.R
Created August 19, 2012 13:31
Install and/or load packages (add to the munge folder in ProjectTemplate)
load_packages <- function(pkgs, repo = "http://ftp.sunet.se/pub/lang/CRAN/"){
invisible(lapply(pkgs, function(pkg) {
req <- function(x) require(x, character.only = TRUE)
if(!suppressWarnings(req(pkg))){
install.packages(pkg, repos = repo)
req(pkg)
}
}))
}
@reinholdsson
reinholdsson / server.R
Created April 7, 2013 12:37
Shiny savings app
library(shiny)
library(rHighcharts)
shinyServer(function(input, output) {
.data <- reactive({
interest <- 1 + ( as.integer(input$interest) / 100 )
start <- as.numeric(input$start)
monthly <- as.numeric(input$monthly)
years <- as.integer(input$years)
@reinholdsson
reinholdsson / countries.geo.json
Last active December 15, 2015 22:19
WDI geoJSON (originally from https://github.com/johan/world.geo.json, but removed countries that doesn't match to WDI data)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@reinholdsson
reinholdsson / readme.md
Last active February 12, 2018 08:28
Programming Links
@reinholdsson
reinholdsson / server.R
Last active January 6, 2023 12:07
Shiny + Redis example
library(rredis)
shinyServer(function(input, output) {
output$show <- renderText({
redisConnect()
res <- redisGet(input$key)
redisClose()
return(res)
})
@reinholdsson
reinholdsson / server.R
Last active June 22, 2021 21:15
Shiny + mongoDB example
library(rmongodb)
shinyServer(function(input, output) {
key <- reactive({
paste(input$key, "data", sep = ".")
})
output$show <- renderText({
<!doctype HTML>
<meta charset = 'utf-8'>
<html>
<head>
<script src='http://code.jquery.com/jquery-1.9.1.min.js' type='text/javascript'></script>
<script src='http://code.highcharts.com/highcharts.js' type='text/javascript'></script>
<script src='http://code.highcharts.com/highcharts-more.js' type='text/javascript'></script>
<style>
@reinholdsson
reinholdsson / README.md
Last active April 19, 2016 10:29
rCharts: Top 50 DVD Rentals
library(rCharts)
library(RJSONIO)
library(data.table)
# Read data from json file
movieJSON <- paste(readLines("movies.json", warn = FALSE), collapse = "")
movieList <- RJSONIO::fromJSON(movieJSON, simplify = F)
movieTable <- rbindlist(lapply(movieList$movies, function(movie) {
data.table(
x = movie$ratings$critics_score,
library(httr)
library(rCharts)
library(RJSONIO)
library(data.table)
# Read data from json file
movieJSON <- paste(readLines("movies.json", warn = FALSE), collapse = "")
movieList <- RJSONIO::fromJSON(movieJSON, simplify = F)
movieTable <- rbindlist(lapply(movieList$movies, function(movie) {
data.table(