Skip to content

Commit f4ddf1b

Browse files
committed
pkgdown github workflow addition and updated based on js package
1 parent 2f71f25 commit f4ddf1b

23 files changed

+211
-85
lines changed

.Rbuildignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
11
^.*\.Rproj$
22
^\.Rproj\.user$
3+
^vignettes/articles$
4+
^_pkgdown\.yml$
5+
^docs$
6+
^pkgdown$
7+
^\.github$

.github/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.html

.github/workflows/pkgdown.yaml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
2+
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
3+
on:
4+
push:
5+
branches: [main, master]
6+
pull_request:
7+
release:
8+
types: [published]
9+
workflow_dispatch:
10+
11+
name: pkgdown.yaml
12+
13+
permissions: read-all
14+
15+
jobs:
16+
pkgdown:
17+
runs-on: ubuntu-latest
18+
# Only restrict concurrency for non-PR jobs
19+
concurrency:
20+
group: pkgdown-${{ github.event_name != 'pull_request' || github.run_id }}
21+
env:
22+
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
23+
permissions:
24+
contents: write
25+
steps:
26+
- uses: actions/checkout@v4
27+
28+
- uses: r-lib/actions/setup-pandoc@v2
29+
30+
- uses: r-lib/actions/setup-r@v2
31+
with:
32+
use-public-rspm: true
33+
34+
- uses: r-lib/actions/setup-r-dependencies@v2
35+
with:
36+
extra-packages: any::pkgdown, any::readr, any::webshot2, local::.
37+
needs: website
38+
39+
- name: Render README.Rmd for GitHub
40+
run: rmarkdown::render("README.Rmd")
41+
shell: Rscript {0}
42+
43+
- name: Render index.Rmd for site
44+
run: rmarkdown::render("index.Rmd")
45+
shell: Rscript {0}
46+
47+
- name: Build site
48+
run: pkgdown::build_site_github_pages(new_process = FALSE, install = TRUE)
49+
shell: Rscript {0}
50+
51+
- name: Deploy to GitHub pages 🚀
52+
if: github.event_name != 'pull_request'
53+
uses: JamesIves/github-pages-deploy-action@v4.5.0
54+
with:
55+
clean: false
56+
branch: gh-pages
57+
folder: docs

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
.Rhistory
33
.RData
44
.Ruserdata
5+
docs

DESCRIPTION

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,5 @@ License: MIT + file LICENSE
1515
Encoding: UTF-8
1616
LazyData: true
1717
RoxygenNote: 7.3.3
18+
Config/Needs/website: rmarkdown
19+
URL: https://grunwaldlab.github.io/metaMapWidgetR/

NAMESPACE

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

3-
export(df_to_tsv)
43
export(meta_map_widget)
54
export(meta_map_widgetOutput)
65
export(renderMeta_map_widget)

R/meta_map_widget.R

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,23 @@
1-
#' <Add Title>
2-
#'
3-
#' <Add Description>
4-
#'
5-
#' @param df dataframe
6-
#' @export
1+
#' @keywords internal
72
df_to_tsv <- function(df) {
83
paste(
9-
paste(colnames(df), collapse = "\t"),
10-
apply(df, 1, function(row) paste(row, collapse = "\t")),
11-
sep = "\n",
4+
c(paste(colnames(df), collapse = "\t"),
5+
apply(df, 1, function(row) paste(row, collapse = "\t"))),
126
collapse = "\n"
137
)
148
}
159

16-
1710
#' @param input A `data.frame`, `tibble`, or a path to tabular data.
1811
#' @param width Width of the widget (CSS units or number).
1912
#' @param height Height of the widget (CSS units or number).
2013
#' @param elementId Optional element ID for the widget.
14+
#' @param sizeVar Size factor rendered by default.
15+
#' @param colorVar Color factor rendered by default.
2116
#'
2217
#' @import htmlwidgets
2318
#'
2419
#' @export
25-
meta_map_widget <- function(input, width = NULL, height = NULL, elementId = NULL) {
20+
meta_map_widget <- function(input, width = NULL, height = NULL, elementId = NULL, sizeVar = '', colorVar = '') {
2621

2722
# Parse input to table
2823
if (is.data.frame(input)) {
@@ -39,14 +34,24 @@ meta_map_widget <- function(input, width = NULL, height = NULL, elementId = NULL
3934
stop(call. = FALSE, 'Input must be a path to a file or a data.frame/tibble.')
4035
}
4136

37+
#Convert NAs to empty strings for all columns
38+
table[] = lapply(table, function(x) {
39+
x[is.na(x)] = ''
40+
return(x)
41+
})
42+
4243
# create widget
4344
createWidget(
4445
name = 'meta_map_widget',
45-
x = df_to_tsv(table),
46+
x = list(
47+
tsv = df_to_tsv(table),
48+
sizeVar = sizeVar,
49+
colorVar = colorVar
50+
),
4651
width = width,
4752
height = height,
4853
package = 'metaMapWidgetR',
49-
elementId = 'map'
54+
elementId = elementId,
5055
)
5156
}
5257

README.Rmd

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,21 @@
22
output: github_document
33
---
44

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)
5+
```{r setup, include=FALSE}
6+
knitr::opts_chunk$set(message = FALSE, warning = FALSE)
247
```
258

9+
# metaMapWidget: R Wrapper for the meta-map-widget Leaflet widget
2610

11+
This package allows users to view the locations of custom data samples and their various attributes using an interactive map widget. The widget may be embedded in Rmd/Quarto documents.
2712

13+
## Installation
2814

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)
15+
For now, metaMapWidgetR is only available on Github and can be installed with devtools:
16+
17+
```{r eval=FALSE}
18+
devtools::install_github('grunwaldlab/metaMapWidgetR')
3619
```
3720

21+
```{r child='vignettes/articles/quickstart.Rmd'}
22+
```

README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
2+
# metaMapWidget: R Wrapper for the meta-map-widget Leaflet widget
3+
4+
This package allows users to view the locations of custom data samples
5+
and their various attributes using an interactive map widget. The widget
6+
may be embedded in Rmd/Quarto documents.
7+
8+
## Installation
9+
10+
For now, metaMapWidgetR is only available on Github and can be installed
11+
with devtools:
12+
13+
``` r
14+
devtools::install_github('grunwaldlab/metaMapWidgetR')
15+
```
16+
17+
## Quick start
18+
19+
This package includes multiple example data sets that are automatically
20+
loaded with the package. After installation, simply run the lines below
21+
to test randomly generated data and customized test columns:
22+
23+
``` r
24+
library(metaMapWidgetR)
25+
26+
example_data_path <- system.file('extdata', 'data.csv', package = 'metaMapWidgetR')
27+
28+
meta_map_widget(example_data_path)
29+
```
30+
31+
![](README_files/figure-gfm/unnamed-chunk-7-1.png)<!-- -->
32+
33+
Or, to get an idea of how this would work with real data:
34+
35+
``` r
36+
library(rgbif)
37+
occ_data <- occ_search(scientificName = "Bombus franklini")
38+
occ_table <- occ_data$data
39+
occ_table$latitude <- occ_table$decimalLatitude
40+
occ_table$longitude <- occ_table$decimalLongitude
41+
meta_map_widget(occ_table, sizeVar='individualCount', colorVar='county')
42+
```
43+
44+
![](README_files/figure-gfm/unnamed-chunk-8-1.png)<!-- -->
148 KB
Loading

0 commit comments

Comments
 (0)