Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ramnathv committed Sep 5, 2014
0 parents commit 017ae49
Show file tree
Hide file tree
Showing 14 changed files with 12,354 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
^.*\.Rproj$
^\.Rproj\.user$
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.Rproj.user
.Rhistory
.RData
9 changes: 9 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Package: datamaps
Type: Package
Title: What the package does (short line)
Version: 1.0
Date: 2014-09-04
Author: Who wrote it
Maintainer: Who to complain to <yourfault@somewhere.net>
Description: More about what it does (maybe more than one line)
License: What license is it under?
7 changes: 7 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Generated by roxygen2 (4.0.2): do not edit by hand

export(datamaps)
export(datamapsOutput)
export(renderDatamaps)
import(htmltools)
import(htmlwidgets)
34 changes: 34 additions & 0 deletions R/datamaps.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#' Datamaps
#'
#' @import htmltools
#' @import htmlwidgets
#' @export
datamaps <- function(..., geographyConfig = list(), width = 700, height = 400){
payload = list(..., geographyConfig = geographyConfig)
if (!is.null(payload$geographyConfig$dataUrl)){
dep = htmltools::htmlDependency(
name = 'dataUrl',
version = '0.1.0',
src = normalizePath(dirname(payload$geographyConfig$dataUrl)),
attachment = basename(payload$geographyConfig$dataUrl)
)
} else {
dep = NULL
}
htmlwidgets::createWidget('datamaps', payload,
width = width, height = height,
dependencies = dep
)
}


#' @export
datamapsOutput <- function(outputId, width = "100%", height = "500px") {
shinyWidgetOutput(outputId, "datamaps", width, height)
}

#' @export
renderDatamaps <- function(expr, env = parent.frame(), quoted = FALSE) {
if (!quoted) { expr <- substitute(expr) } # force quoted
shinyRenderWidget(expr, datamapsOutput, env, quoted = TRUE)
}
73 changes: 73 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
## Datamaps

This is an htmlwidgets binding for the datamaps package.

### Simple Map

Status: WORKING

```r
library(datamaps)
datamaps()
datamaps(scope = 'usa')
```

### Shiny App

Status: WORKING

```r
library(shiny)
ui = bootstrapPage(
selectInput('def_fill', 'Select Color', c('blue', 'green')),
datamapsOutput('mymap', 800, 400)
)

server = function(input, output, session){
output$mymap <- renderDatamaps(
datamaps(
fills = list(defaultFill = input$def_fill)
)
)
}

runApp(list(ui = ui, server = server), launch.browser = rstudio::viewer)
```

### Map with External Data

Status: WORKING

```r
datamaps(
scope = 'pcs',
geographyConfig = list(dataUrl = 'data/pcs.json'),
width = 900, height = 800
)
```

### Shiny App with External Data

Status: NOT WORKING

> Uncaught Error: Attachment dataUrl/1 not found in document
```r
library(shiny)
ui = bootstrapPage(
selectInput('def_fill', 'Select Color', c('blue', 'green')),
datamapsOutput('mymap', 900, 800)
)

server = function(input, output, session){
output$mymap <- renderDatamaps(
datamaps(
scope = 'pcs',
geographyConfig = list(dataUrl = 'data/pcs.json'),
fills = list(defaultFill = input$def_fill)
)
)
}

runApp(list(ui = ui, server = server), launch.browser = rstudio::viewer)
```
1 change: 1 addition & 0 deletions data/pcs.json

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions datamaps.Rproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Version: 1.0

RestoreWorkspace: Default
SaveWorkspace: Default
AlwaysSaveHistory: Default

EnableCodeIndexing: Yes
UseSpacesForTab: Yes
NumSpacesForTab: 2
Encoding: UTF-8

RnwWeave: Sweave
LaTeX: pdfLaTeX

BuildType: Package
PackageUseDevtools: Yes
PackageInstallArgs: --no-multiarch --with-keep.source
14 changes: 14 additions & 0 deletions inst/htmlwidgets/datamaps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
HTMLWidgets.widget({
name: "datamaps",
type: "output",
renderValue: function(el, payload){
el.innerHTML = ""
payload.element = el
if (payload.geographyConfig.dataUrl){
console.log('attaching dataUrl')
payload.geographyConfig.dataUrl = HTMLWidgets.getAttachmentUrl('dataUrl', 1)
console.log(HTMLWidgets.getAttachmentUrl('dataUrl', 1))
}
var map = new Datamap(payload)
}
})
9 changes: 9 additions & 0 deletions inst/htmlwidgets/datamaps.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
dependencies:
- name: d3
version: 3.4.11
src: "htmlwidgets/lib/d3"
script: [d3.v3.min.js, topojson.v1.min.js]
- name: datamaps
version: 0.3.4
src: "htmlwidgets/lib/datamaps"
script: datamaps.all.js
5 changes: 5 additions & 0 deletions inst/htmlwidgets/lib/d3/d3.v3.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions inst/htmlwidgets/lib/d3/topojson.v1.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 017ae49

Please sign in to comment.