Skip to content

Commit 7664a94

Browse files
committed
Merge branch 'dev' of https://github.com/grunwaldlab/metaMapWidgetR into dev
2 parents cba6c86 + 5bc9d0c commit 7664a94

7 files changed

Lines changed: 65 additions & 40 deletions

File tree

NAMESPACE

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# Generated by roxygen2: do not edit by hand
22

33
export(df_to_tsv)
4-
export(hello)
54
export(meta_map_widget)
65
export(meta_map_widgetOutput)
76
export(renderMeta_map_widget)

R/hello.R

Lines changed: 0 additions & 6 deletions
This file was deleted.

R/meta_map_widget.R

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,46 +12,45 @@ df_to_tsv <- function(df) {
1212
collapse = "\n"
1313
)
1414
}
15+
16+
17+
#' @param input A `data.frame`, `tibble`, or a path to tabular data.
1518
#' @param width Width of the widget (CSS units or number).
1619
#' @param height Height of the widget (CSS units or number).
1720
#' @param elementId Optional element ID for the widget.
1821
#'
1922
#' @import htmlwidgets
2023
#'
2124
#' @export
25+
meta_map_widget <- function(input, width = NULL, height = NULL, elementId = NULL) {
2226

23-
meta_map_widget <- function(width = NULL, height = NULL, elementId = NULL) {
24-
25-
#uncomment below for test data generation
26-
27-
#df <- data.frame(
28-
#latitude = runif(20, min = 34.0, max = 45.0),
29-
#longitude = runif(20, min = -120.0, max = -75.0),
30-
#name = paste("Sample", 1:20),
31-
#color_by = c(rep('type;proportion_infected;comically_small_test_column', 10), rep('type', 10)),
32-
#type = sample(c("Nursery", "Forest", "Urban", "Farm"), 20, replace = TRUE),
33-
#proportion_infected = runif(20),
34-
#comically_small_test_column = sample(c(0.000001898, 0.0000000023678876, 0.0024), 20, replace = TRUE)
35-
#)
27+
# Parse input to table
28+
if (is.data.frame(input)) {
29+
table <- input
30+
} else if (is.character(input) && length(input) == 1) {
31+
if (endsWith(input, '.tsv')) {
32+
table <- read.csv(input, sep = '\t')
33+
} else if (endsWith(input, '.csv')) {
34+
table <- read.csv(input, sep = ',')
35+
} else {
36+
stop(call. = FALSE, 'Invalid table format. Paths to input data must end in .tsv or .csv and be in the corresponding format.')
37+
}
38+
} else {
39+
stop(call. = FALSE, 'Input must be a path to a file or a data.frame/tibble.')
40+
}
3641

37-
df <- read.table(
38-
"data.tsv",
39-
header = TRUE,
40-
sep = ";",
41-
quote = "\"",
42-
stringsAsFactors = FALSE
43-
)
4442
# create widget
4543
createWidget(
4644
name = 'meta_map_widget',
47-
x = df_to_tsv(df),
45+
x = df_to_tsv(table),
4846
width = width,
4947
height = height,
5048
package = 'metaMapWidgetR',
5149
elementId = 'map'
5250
)
5351
}
5452

53+
5554
#' Shiny bindings for meta_map_widget
5655
#'
5756
#' Output and render functions for using meta_map_widget within Shiny
@@ -73,6 +72,7 @@ meta_map_widgetOutput <- function(outputId, width = '100%', height = '400px'){
7372
htmlwidgets::shinyWidgetOutput(outputId, 'meta_map_widget', width, height, package = 'metaMapWidgetR')
7473
}
7574

75+
7676
#' @rdname meta_map_widget-shiny
7777
#' @export
7878
renderMeta_map_widget <- function(expr, env = parent.frame(), quoted = FALSE) {

README.Rmd

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
output: github_document
3+
---
4+
5+
## metaMapWidget: R Wrapper for the meta-map-widget Leaflet widget
6+
7+
```{r}
8+
library(metaMapWidgetR)
9+
df <- tibble::tibble(
10+
latitude = runif(20, min = 34.0, max = 45.0),
11+
longitude = runif(20, min = -120.0, max = -75.0),
12+
name = paste("Sample", 1:20),
13+
color_by = c(rep('type;proportion_infected;comically_small_test_column', 10), rep('type', 10)),
14+
type = sample(c("Nursery", "Forest", "Urban", "Farm"), 20, replace = TRUE),
15+
proportion_infected = runif(20),
16+
comically_small_test_column = sample(c(0.000001898, 0.0000000023678876, 0.0024), 20, replace = TRUE)
17+
)
18+
print(df)
19+
20+
example_data_path <- system.file('extdata', 'data.csv', package = 'metaMapWidgetR')
21+
22+
meta_map_widget(df)
23+
meta_map_widget(example_data_path)
24+
```
25+
26+
27+
28+
29+
```{r}
30+
library(rgbif)
31+
occ_data <- occ_search(scientificName = "Bombus franklini")
32+
occ_table <- occ_data$data
33+
occ_table$latitude <- occ_table$decimalLatitude
34+
occ_table$longitude <- occ_table$decimalLongitude
35+
meta_map_widget(occ_table)
36+
```
37+

data.tsv

Lines changed: 0 additions & 7 deletions
This file was deleted.

inst/extdata/data.csv

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
latitude,longitude,name,color_by,type,proportion_infected,comically_small_test_column
2+
44.10388,-92.11876,Sample 4,"type;proportion_infected;comically_small_test_column",Farm,0.95618302,0.0024
3+
39.66152,-109.55498,Sample 5,"type;proportion_infected;comically_small_test_column",Forest,0.12877409,0.0024
4+
42.88411,-83.22741,Sample 6,"type;proportion_infected;comically_small_test_column",Nursery,0.51290344,0.000001898
5+
34.99084,-77.66492,Sample 7,"type;proportion_infected;comically_small_test_column",Urban,0.68911320,0.0024
6+
40.21736,-115.33987,Sample 8,"type;proportion_infected;comically_small_test_column",Forest,0.04388271,0.0000000023678876
7+
37.55891,-98.44730,Sample 9,"type;proportion_infected;comically_small_test_column",Farm,0.87730066,0.0024

inst/htmlwidgets/lib/meta-map-widget-0.1/meta-map-min.js

Lines changed: 0 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)