Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Carson/feature/plotly crosstalk #281

Closed
4 changes: 4 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ URL: http://rstudio.github.io/leaflet/
BugReports: https://github.com/rstudio/leaflet/issues
Imports:
base64enc,
crosstalk,
htmlwidgets,
htmltools,
magrittr,
Expand All @@ -50,4 +51,7 @@ Suggests:
rgdal,
R6,
RJSONIO
Remotes:
rstudio/crosstalk,
jcheng5/plotly@joe/feature/crosstalk
RoxygenNote: 5.0.1
Copy link
Contributor Author

@cpsievert cpsievert Aug 26, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is here just for the time being since we need to access plotly's "global" crosstalk options, as I'm getting here

3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

S3method("[",leaflet_awesome_icon_set)
S3method("[",leaflet_icon_set)
S3method(pointData,SharedData)
S3method(pointData,SpatialPoints)
S3method(pointData,SpatialPointsDataFrame)
S3method(pointData,data.frame)
S3method(pointData,default)
S3method(pointData,matrix)
S3method(polygonData,SharedData)
export("%>%")
export(JS)
export(WMSTileOptions)
Expand Down Expand Up @@ -93,5 +95,6 @@ export(setMaxBounds)
export(setView)
export(showGroup)
export(tileOptions)
import(crosstalk)
importFrom(htmlwidgets,JS)
importFrom(magrittr,"%>%")
16 changes: 16 additions & 0 deletions R/normalize.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ doResolveFormula.data.frame = function(data, f) {
eval(f[[2]], data, environment(f))
}

doResolveFormula.SharedData = function(data, f) {
doResolveFormula(data$data(withSelection = TRUE, withFilter = FALSE, withKey = TRUE), f)
}

doResolveFormula.map = function(data, f) {
eval(f[[2]], data, environment(f))
}
Expand Down Expand Up @@ -160,6 +164,12 @@ pointData.SpatialPointsDataFrame = function(obj) {
)
}

#' @export
pointData.SharedData = function(obj) {
pointData(obj$data(withSelection = FALSE,
withFilter = FALSE, withKey = FALSE))
}

# A simple polygon is a list(lng=numeric(), lat=numeric()). A compound polygon
# is a list of simple polygons. This function returns a list of compound
# polygons, so list(list(list(lng=..., lat=...))). There is also a bbox
Expand Down Expand Up @@ -221,6 +231,12 @@ polygonData.SpatialLinesDataFrame = function(obj) {
polygonData(sp::SpatialLines(obj@lines))
}

#' @export
polygonData.SharedData = function(obj) {
polygonData(obj$data(withSelection = FALSE,
withFilter = FALSE, withKey = FALSE))
}

dfbbox = function(df) {
suppressWarnings(rbind(
lng = range(df$lng, na.rm = TRUE),
Expand Down
15 changes: 14 additions & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,22 @@ filterNULL = function(x) {
#' @param method the name of the JavaScript method to invoke
#' @param ... unnamed arguments to be passed to the JavaScript method
#' @rdname dispatch
#' @import crosstalk
#' @export
invokeMethod = function(map, data, method, ...) {
args = evalFormula(list(...), data)
crosstalkOptions <- if (crosstalk::is.SharedData(data)) {
map$dependencies <- c(map$dependencies, crosstalk::crosstalkLibs())
sd <- data
data <- sd$data()
list(
ctKey = sd$key(),
ctGroup = sd$groupName()
)
} else {
NULL
}

args = c(evalFormula(list(...), data), list(crosstalkOptions))

dispatch(map,
method,
Expand Down
Loading