Skip to content

Commit eca762c

Browse files
committed
first commit
0 parents  commit eca762c

19 files changed

Lines changed: 386 additions & 0 deletions

.Rbuildignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
^flowmapblue\.Rproj$
2+
^\.Rproj\.user$

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.Rhistory
2+
.Rproj.user
3+
.idea

DESCRIPTION

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Package: flowmapblue
2+
Title: Flow map rendering
3+
Version: 0.0.1
4+
Authors@R:
5+
person(given = "Ilya",
6+
family = "Boyandin",
7+
role = c("aut", "cre"),
8+
email = "ilya@boyandin.me",
9+
comment = c(ORCID = "0000-0001-5585-7587"))
10+
Description: Rendering interactive flow maps to visualize numbers of movements between locations (origin-destination data).
11+
License: `use_mit_license()`
12+
Encoding: UTF-8
13+
LazyData: true
14+
Roxygen: list(markdown = TRUE)
15+
RoxygenNote: 7.1.1

LICENSE

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Copyright 2020 Ilya Boyandin
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of
4+
this software and associated documentation files (the "Software"), to deal in
5+
the Software without restriction, including without limitation the rights to
6+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
7+
the Software, and to permit persons to whom the Software is furnished to do so,
8+
subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

NAMESPACE

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Generated by roxygen2: do not edit by hand
2+
3+
export(flowmapblue)
4+
export(flowmapblueOutput)
5+
export(renderFlowmapblue)
6+
import(htmlwidgets)

R/flowmapblue.R

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#' <Add Title>
2+
#'
3+
#' <Add Description>
4+
#'
5+
#' @import htmlwidgets
6+
#'
7+
#' @export
8+
flowmapblue <- function(
9+
locations, flows,
10+
mapboxAccessToken = NULL,
11+
clustering = TRUE,
12+
animation = FALSE,
13+
darkMode = FALSE
14+
) {
15+
16+
# pass the data and settings using 'x'
17+
x <- list(
18+
locations = locations,
19+
flows = flows,
20+
mapboxAccessToken = mapboxAccessToken,
21+
clustering = clustering,
22+
animation = animation,
23+
darkMode = darkMode
24+
)
25+
26+
# create widget
27+
htmlwidgets::createWidget(
28+
name = 'flowmapblue',
29+
x,
30+
width = NULL,
31+
height = NULL,
32+
package = 'flowmapblue'
33+
)
34+
}
35+
36+
#' Shiny bindings for flowmapblue
37+
#'
38+
#' Output and render functions for using flowmapblue within Shiny
39+
#' applications and interactive Rmd documents.
40+
#'
41+
#' @param outputId output variable to read from
42+
#' @param width,height Must be a valid CSS unit (like \code{'100\%'},
43+
#' \code{'400px'}, \code{'auto'}) or a number, which will be coerced to a
44+
#' string and have \code{'px'} appended.
45+
#' @param expr An expression that generates a flowmapblue
46+
#' @param env The environment in which to evaluate \code{expr}.
47+
#' @param quoted Is \code{expr} a quoted expression (with \code{quote()})? This
48+
#' is useful if you want to save an expression in a variable.
49+
#'
50+
#' @name flowmapblue-shiny
51+
#'
52+
#' @export
53+
flowmapblueOutput <- function(outputId, width = '100%', height = '400px'){
54+
htmlwidgets::shinyWidgetOutput(outputId, 'flowmapblue', width, height, package = 'flowmapblue')
55+
}
56+
57+
#' @rdname flowmapblue-shiny
58+
#' @export
59+
renderFlowmapblue <- function(expr, env = parent.frame(), quoted = FALSE) {
60+
if (!quoted) { expr <- substitute(expr) } # force quoted
61+
htmlwidgets::shinyRenderWidget(expr, flowmapblueOutput, env, quoted = TRUE)
62+
}

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Flowmap.blue R widget
2+
3+
This is an R widget for [Flowmap.blue](http://flowmap.blue).
4+
Rendering interactive flow maps to visualize numbers of movements between locations (origin-destination data).
5+
6+
7+
#### Installation
8+
9+
You can install the package from GitHub as follows:
10+
11+
devtools::install_github("FlowmapBlue/flowmapblue.R")
12+
library(flowmapblue);
13+
14+
15+
16+
#### Usage
17+
18+
locations <- read.csv('https://gist.githubusercontent.com/ilyabo/a7b9701424257146b571149d92a14926/raw/2e9e1e9bcf64cf0090781b451037229ccb78e1b1/locations.csv')
19+
flows <- read.csv('https://gist.githubusercontent.com/ilyabo/a7b9701424257146b571149d92a14926/raw/2e9e1e9bcf64cf0090781b451037229ccb78e1b1/flows.csv')
20+
mapboxAccessToken = 'YOUR_MAPBOX_ACCESS_TOKEN'
21+
flowmapblue(locations, flows, mapboxAccessToken, clustering=TRUE, darkMode=TRUE, animation=FALSE)

flowmapblue.Rproj

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Version: 1.0
2+
3+
RestoreWorkspace: No
4+
SaveWorkspace: No
5+
AlwaysSaveHistory: Default
6+
7+
EnableCodeIndexing: Yes
8+
UseSpacesForTab: Yes
9+
NumSpacesForTab: 2
10+
Encoding: UTF-8
11+
12+
RnwWeave: Sweave
13+
LaTeX: pdfLaTeX
14+
15+
AutoAppendNewline: Yes
16+
StripTrailingWhitespace: Yes
17+
LineEndingConversion: Posix
18+
19+
BuildType: Package
20+
PackageUseDevtools: Yes
21+
PackageInstallArgs: --no-multiarch --with-keep.source
22+
PackageRoxygenize: rd,collate,namespace

inst/htmlwidgets/flowmapblue.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
HTMLWidgets.widget({
2+
3+
name: 'flowmapblue',
4+
5+
type: 'output',
6+
7+
factory: function(el, width, height) {
8+
9+
// TODO: define shared variables for this instance
10+
11+
return {
12+
13+
renderValue: function(x) {
14+
flowmapBlue.init({
15+
locations: HTMLWidgets.dataframeToD3(x.locations),
16+
flows: HTMLWidgets.dataframeToD3(x.flows),
17+
container: el,
18+
mapboxAccessToken: x.mapboxAccessToken,
19+
clustering: x.clustering,
20+
animation: x.animation,
21+
darkMode: x.darkMode,
22+
});
23+
},
24+
25+
resize: function(width, height) {
26+
// TODO: code to re-render the widget with a new size
27+
}
28+
29+
};
30+
}
31+
});

inst/htmlwidgets/flowmapblue.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# (uncomment to add a dependency)
2+
# dependencies:
3+
# - name:
4+
# version:
5+
# src:
6+
# script:
7+
# stylesheet:
8+
9+
dependencies:
10+
- name: flowmapblue
11+
version: 0.0.1
12+
src: htmlwidgets/lib
13+
script:
14+
- flowmap-blue.min.js

0 commit comments

Comments
 (0)