Skip to content

Instantly share code, notes, and snippets.

@diegovalle
diegovalle / CreateRoutes.R
Created April 13, 2011 03:09
Decode polylines obtained from Google Maps
library(maptools)
library(maps)
library(mapdata)
library(rjson)
library(stringr)
library(RCurl)
library(ggplot2)
GetDirections <- function(from, to) {
@trestletech
trestletech / server.R
Last active May 25, 2017 21:30
An example of doing prolonged, iterative computation in Shiny.
library(shiny)
shinyServer(function(input, output, session) {
# The number of iterations to perform
maxIter <- 50
# Track the start and elapsed time
startTime <- Sys.time()
output$elapsed <- renderText({
@trestletech
trestletech / server.R
Last active February 2, 2022 09:47
A Shiny app combining the use of dplyr and SQLite. The goal is to demonstrate a full-fledged, database-backed user authorization framework in Shiny.
library(shiny)
library(dplyr)
library(lubridate)
# Load libraries and functions needed to create SQLite databases.
library(RSQLite)
library(RSQLite.extfuns)
saveSQLite <- function(data, name){
path <- dplyr:::db_location(filename=paste0(name, ".sqlite"))
@gisminister
gisminister / README.md
Last active April 11, 2024 18:52
Markercluster pie charts

The map shows traffic accidents recorded in Oslo, Norway, for the year 2013.

The Leaflet Markercluster plugin is wonderful. Since the markerclusters are divIcons you can put whatever you want inside them using the iconCreateFunction. I wanted my clusters to reveal more information than just the marker count and figured a pie chart would do the job. So I told the iconCreateFunction to do some D3 magic and this is the result.

The example is a bit more complicated than necessary due to how my dataset is structured. But if you take a look at the defineClusterIcon() function you'll see that I use d3.nest() to build a dataset for the pie chart based on a given property from all the cluster's children. Then I pass this dataset over to the bakeThePie() function together with instructions on how to style the chart. The function returns svg markup which in turn is placed inside the divIcon.

Feel free to suggest improvements.

anonymous
anonymous / lag_gen
Created May 18, 2014 09:42
R example of dplyr's mutate and lag with magrittr to flexibly add lags to a data.frame
#
# Example of dplyr's mutate and lag with magrittr's %>%
# to flexibly add lags to a data.frame
#
library(dplyr)
library(magrittr) # >= v.1.0.1
# A function to generate a mutate call
lag_gen <- function(x, lags)
{
@jcheng5
jcheng5 / server.R
Last active April 17, 2018 01:32 — forked from Athospd/server.R
library(shiny)
library(magrittr)
shinyServer(function(input, output, session) {
#__________________________________________________________________________________
# The main named list that will be used in many other tasks.
listN <- reactiveValues()
makeReactiveBinding("listN")
@cpsievert
cpsievert / plotly-docs.R
Last active August 20, 2018 15:04
Plotly examples
# install the new/experimental plotly R package
# devtools::install_github("ropensci/plotly@carson-dsl")
# ----------------------------------------------------------------------
# https://plot.ly/r/3d-line-plots/
# ----------------------------------------------------------------------
library(plotly)
# initiate a 100 x 3 matrix filled with zeros
@psychemedia
psychemedia / numbers2words.R
Created July 12, 2015 00:12
R function to convert numbers to words
#https://github.com/ateucher/useful_code/blob/master/R/numbers2words.r
numbers2words <- function(x){
## Function by John Fox found here:
## http://tolstoy.newcastle.edu.au/R/help/05/04/2715.html
## Tweaks by AJH to add commas and "and"
helper <- function(x){
digits <- rev(strsplit(as.character(x), "")[[1]])
nDigits <- length(digits)
if (nDigits == 1) as.vector(ones[digits])
@ramnathv
ramnathv / README.md
Last active February 11, 2016 21:09
Import D3 Block in RStudio

Livecoding D3 in RStudio

This is a proof-of-concept on how one can use RStudio to livecode D3 visualizations.

Usage

You will need to install a couple of packages before getting started

devtools::install_github("yihui/servr")
@lopspower
lopspower / README.md
Last active July 23, 2024 13:00
Hexadecimal color code for transparency

Hexadecimal color code for transparency

Twitter

How to set transparency with hex value ?

For example, you want to set 40% alpha transparence to #000000 (black color), you need to add 66 like this #66000000.

Download This sample on Google Play Store