-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 017ae49
Showing
14 changed files
with
12,354 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
^.*\.Rproj$ | ||
^\.Rproj\.user$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.Rproj.user | ||
.Rhistory | ||
.RData |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
``` |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.