-
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
Showing
12 changed files
with
306 additions
and
109 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
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,45 @@ | ||
|
||
|
||
#' Add a select menu above a map | ||
#' | ||
#' Use this to update variable used in \code{d3_cartogram}. | ||
#' | ||
#' @param map A \code{d3_cartogram} \code{htmlwidget} object. | ||
#' @param label Display label for the control, or \code{NULL} for no label. | ||
#' @param choices List of values to select from. Can be a named list. Values must be variables names. | ||
#' | ||
#' @export | ||
#' | ||
#' @importFrom shiny selectInput | ||
#' @importFrom htmltools doRenderTags | ||
#' | ||
#' @examples | ||
#' # todo | ||
add_select_input <- function(map, label = NULL, choices) { | ||
id <- paste0("select-", sample.int(1e9, 1)) | ||
select_ <- selectInput( | ||
inputId = id, | ||
label = label, | ||
choices = choices, | ||
multiple = FALSE, | ||
selectize = FALSE | ||
) | ||
select_$children[[2]]$children[[1]]$attribs$class <- "form-control custom-select" | ||
select_html <- doRenderTags(select_) | ||
choices <- unlist(choices, use.names = FALSE) | ||
if (is.null(map$x$options$data)) | ||
stop("No data !", call. = FALSE) | ||
data_ <- map$x$options$data | ||
if (!all(choices %in% names(data_))) | ||
stop("Choices are not all columns names !", call. = FALSE) | ||
map$x$options$select <- TRUE | ||
.r2d3map_opt( | ||
map, "select_opts", | ||
select_html = select_html, | ||
id = id, choices = choices | ||
) | ||
} | ||
|
||
|
||
|
||
|
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
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
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
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
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,24 @@ | ||
|
||
|
||
# helper to extract data | ||
extract_data <- function(x) { | ||
UseMethod("extract_data") | ||
} | ||
extract_data.SpatialPolygonsDataFrame <- function(x) { | ||
return(x@data) | ||
} | ||
extract_data.data.frame <- function(x) { | ||
return(x) | ||
} | ||
extract_data.sf <- function(x) { | ||
x <- as.data.frame(x) | ||
colsf <- attr(x, "sf_column") | ||
x[[colsf]] <- NULL | ||
return(x) | ||
} | ||
extract_data.NULL <- function(x) { | ||
NULL | ||
} | ||
|
||
|
||
|
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
Oops, something went wrong.