Drop support for orphaned plotly package
Change-Id: I59e5339c613fc1eef89bb81afc0c260e2f60ed16
diff --git a/DESCRIPTION b/DESCRIPTION
index 45b8220..900f120 100644
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -43,7 +43,6 @@
highcharter,
jsonlite,
keyring,
- plotly,
htmlwidgets,
utils,
httr,
diff --git a/NAMESPACE b/NAMESPACE
index a3c590f..6017fe9 100644
--- a/NAMESPACE
+++ b/NAMESPACE
@@ -9,7 +9,6 @@
export(defaultAssociationScoreFunctions)
export(expand_grid)
export(geom_freq_by_year_ci)
-export(ggplotly)
export(group_by)
export(hc_add_onclick_korap_search)
export(hc_freq_by_year_ci)
@@ -76,12 +75,9 @@
importFrom(ggplot2,layer)
importFrom(ggplot2,scale_x_continuous)
importFrom(ggplot2,theme)
-importFrom(htmlwidgets,onRender)
-importFrom(htmlwidgets,saveWidget)
importFrom(jsonlite,fromJSON)
importFrom(lubridate,year)
importFrom(magrittr,"%>%")
-importFrom(plotly,ggplotly)
importFrom(stats,prop.test)
importFrom(tibble,add_column)
importFrom(tibble,as_tibble)
diff --git a/NEWS.md b/NEWS.md
index e299e61..ec221e3 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -3,6 +3,7 @@
## Changes
- collocationScoreQuery method added
- hc_add_onclick_korap_search function added
+- support for orphaned plotly package dropped
# RKorAPClient 0.5.9
diff --git a/R/misc.R b/R/misc.R
index 4529d7a..108d942 100644
--- a/R/misc.R
+++ b/R/misc.R
@@ -133,10 +133,12 @@
scale_x_continuous(breaks = function(x) seq(ceiling(x[1]), floor(x[2]), by = 1 + floor(((x[2]-x[1])/30)))))
}
+#'
#' @importFrom ggplot2 ggproto aes GeomPoint
-GeomClickPoint <- ggproto(
+#'
+GeomClickPoint <- ggplot2::ggproto(
"GeomPoint",
- GeomPoint,
+ ggplot2::GeomPoint,
required_aes = c("x", "y"),
default_aes = aes(
shape = 19, colour = "black", size = 1.5, fill = NA,
@@ -151,8 +153,8 @@
#' @importFrom ggplot2 layer
geom_click_point <- function(mapping = NULL, data = NULL, stat = "identity",
- position = "identity", na.rm = FALSE, show.legend = NA,
- inherit.aes = TRUE, url = NA, ...) {
+ position = "identity", na.rm = FALSE, show.legend = NA,
+ inherit.aes = TRUE, url = NA, ...) {
layer(
geom = GeomClickPoint, mapping = mapping, data = data, stat = stat,
position = position, show.legend = show.legend, inherit.aes = inherit.aes,
@@ -160,55 +162,3 @@
)
}
-
-#' @importFrom htmlwidgets onRender
-tooltip2hyperlink <- function(p, attribute="webUIRequestUrl") {
- pattern <- paste0(attribute, ": ([^<]+)")
- for(i in grep(attribute, p$x$data)) {
- x <- p[["x"]][["data"]][[i]][["text"]]
- m <- regexpr(pattern, x)
- matches <- sub(paste0(attribute, ": "), "", regmatches(x, m))
- p$x$data[[i]]$customdata <- matches
- p[["x"]][["data"]][[i]][["text"]] <- sub(paste0(attribute, ":[^<]*<br ?/?>"), "", p[["x"]][["data"]][[i]][["text"]] )
- }
- onRender(p, "function(el, x) { el.on('plotly_click', function(d) { var url=d.points[0].customdata; if(url) { window.open(url, 'korap') } })}")
-}
-
-#' Experimental: Convert ggplot2 to plotly with hyperlinks to KorAP queries
-#'
-#' \code{RKorAPClient::ggplotly} converts a \code{ggplot2::ggplot()} object to a plotly
-#' object with hyperlinks from data points to corresponding KorAP queries.
-#' \bold{Warning:} This function may be moved to a new package.
-#'
-#' @param p a ggplot object.
-#' @param tooltip a character vector specifying which aesthetic mappings to show
-#' in the tooltip. If you want hyperlinks to KorAP queries you need to include
-#' \code{"url"} here.
-#' @param ... Other arguments passed to \code{plotly::ggplotly}
-#'
-#' @rdname misc-functions
-#'
-#' @examples
-#' library(ggplot2)
-#' kco <- new("KorAPConnection", verbose=TRUE)
-#' \donttest{year <- (2003:2011)}\dontshow{year <- c(2005)}
-#' \donttest{condition <- c("textDomain = /Wirtschaft.*/", "textDomain != /Wirtschaft.*/")}\dontshow{condition <- c("textDomain = /Wirtschaft.*/")}
-#' g <- expand_grid(condition, year) %>%
-#' cbind(frequencyQuery(kco, "[tt/l=Heuschrecke]",
-#' paste0(.$condition," & pubDate in ", .$year))) %>%
-#' ipm() %>%
-#' ggplot(aes(year, ipm, fill = condition, color = condition)) +
-#' ## theme_light(base_size = 20) +
-#' geom_freq_by_year_ci()
-#' p <- ggplotly(g)
-#' print(p)
-#' ## saveWidget(p, paste0(tmpdir(), "heuschrecke.html")
-#'
-#'
-#' @importFrom plotly ggplotly
-#' @importFrom htmlwidgets saveWidget
-#' @export
-ggplotly <- function(p = ggplot2::last_plot(), tooltip = c("x", "y", "colour", "url"), ...) {
- pp <- plotly::ggplotly(p = p, tooltip = tooltip, ...)
- tooltip2hyperlink(pp)
-}
diff --git a/demo/alternativesOverTime.R b/demo/alternativesOverTime.R
index eb85ac8..07019bd 100755
--- a/demo/alternativesOverTime.R
+++ b/demo/alternativesOverTime.R
@@ -4,8 +4,6 @@
#
library(RKorAPClient)
library(ggplot2)
-library(plotly)
-library(htmlwidgets)
alternativesOverTime <- function(alternatives, years, kco = new("KorAPConnection", verbose=TRUE)) {
df <- expand_grid(Variant = alternatives, year = years) %>%
@@ -16,8 +14,7 @@
ggtitle(paste0(alternatives, collapse = " vs. ")) +
xlab("TIME") +
ylab(sprintf("Observed frequency ratio"))
- ppp <- RKorAPClient::ggplotly(g)
- print(ppp)
+ print(g)
df
}
diff --git a/demo/conditionsOverTime.R b/demo/conditionsOverTime.R
index b23d2bf..ccd5592 100644
--- a/demo/conditionsOverTime.R
+++ b/demo/conditionsOverTime.R
@@ -6,7 +6,6 @@
#install_git("https://korap.ids-mannheim.de/gerrit/KorAP/RKorAPClient", upgrade="never")
library(RKorAPClient)
library(ggplot2)
-library(plotly)
conditionsOverTime <- function(query, conditions, years, kco = new("KorAPConnection", verbose = TRUE)) {
g <- expand_grid(condition = conditions, year = years) %>%
@@ -17,8 +16,7 @@
xlab("TIME") +
labs(color="Virtual Corpus", fill="Virtual Corpus") +
ylab(sprintf("Observed frequency/million of \u201c%s\u201d", query))
- p <- RKorAPClient::ggplotly(g)
- print(p)
+ print(g)
}
conditionsOverTime("[tt/l=Heuschrecke]", c("textClass = /natur.*/", "textClass=/politik.*/", "textClass=/wirtschaft.*/"), (2002:2018))
diff --git a/demo/frequenciesOverTime.R b/demo/frequenciesOverTime.R
index 56b576f..aadd0d2 100644
--- a/demo/frequenciesOverTime.R
+++ b/demo/frequenciesOverTime.R
@@ -4,7 +4,6 @@
#
library(RKorAPClient)
library(ggplot2)
-library(plotly)
freqPerYear <- function(query, kco = new("KorAPConnection", verbose = TRUE)) {
g <- data.frame(year = 2000:2018) %>%
@@ -15,8 +14,7 @@
geom_freq_by_year_ci() +
xlab("TIME") +
ylab(sprintf("Observed frequency/million of \u201c%s\u201d", query))
- p <- RKorAPClient::ggplotly(g)
- print(p)
+ print(g)
df
}
#df <- freqPerYear("Car-Bikini")
diff --git a/demo/regional.R b/demo/regional.R
index 05a3b6d..9480d67 100755
--- a/demo/regional.R
+++ b/demo/regional.R
@@ -3,7 +3,6 @@
library(ggplot2)
library(raster)
library(broom)
-library(plotly)
library(htmlwidgets)
devAskNewPage(ask = FALSE)
@@ -58,14 +57,8 @@
}
}
plot <- updatePlot(query, map, regions)
- pp <- ggplotly(plot)
- for (i in 1:nrow(regions)) {
- j <- grep(paste0(regions$region[i], "\""), pp$x$data, perl=TRUE)
- pp$x$data[[j]]$customdata <- regions[i,]$url
- }
- ppp <- onRender(pp, "function(el, x) { el.on('plotly_click', function(d) { var url=d.points[0].data.customdata; window.open(url, 'korap') })}")
- print(ppp)
- pp
+ print(plot)
+ plot
}
updatePlot <- function(query, map, regions) {
diff --git a/man/misc-functions.Rd b/man/misc-functions.Rd
index b0d9c0d..e3c0630 100644
--- a/man/misc-functions.Rd
+++ b/man/misc-functions.Rd
@@ -7,7 +7,6 @@
\alias{percent}
\alias{queryStringToLabel}
\alias{geom_freq_by_year_ci}
-\alias{ggplotly}
\title{Add confidence interval and relative frequency variables}
\usage{
ci(df, x = totalResults, N = total, conf.level = 0.95)
@@ -19,8 +18,6 @@
queryStringToLabel(data, pubDateOnly = FALSE, excludePubDate = FALSE)
geom_freq_by_year_ci(mapping = aes(ymin = conf.low, ymax = conf.high), ...)
-
-ggplotly(p = ggplot2::last_plot(), tooltip = c("x", "y", "colour", "url"), ...)
}
\arguments{
\item{df}{table returned from \code{\link{frequencyQuery}}}
@@ -40,13 +37,7 @@
\item{mapping}{Set of aesthetic mappings created by aes() or aes_(). If specified and inherit.aes = TRUE (the default), it is combined with the default mapping at the top level of the plot. You must supply mapping if there is no plot mapping.}
-\item{...}{Other arguments passed to \code{plotly::ggplotly}}
-
-\item{p}{a ggplot object.}
-
-\item{tooltip}{a character vector specifying which aesthetic mappings to show
-in the tooltip. If you want hyperlinks to KorAP queries you need to include
-\code{"url"} here.}
+\item{...}{Other arguments passed to geom_ribbon, geom_line, and geom_click_point.}
}
\value{
original table with additional column \code{ipm} and converted columns \code{conf.low} and \code{conf.high}
@@ -72,10 +63,6 @@
Experimental convenience function for plotting typical frequency by year graphs with confidence intervals using ggplot2.
\bold{Warning:} This function may be moved to a new package.
-
-\code{RKorAPClient::ggplotly} converts a \code{ggplot2::ggplot()} object to a plotly
-object with hyperlinks from data points to corresponding KorAP queries.
-\bold{Warning:} This function may be moved to a new package.
}
\details{
Given a table with columns \code{f}, \code{conf.low}, and \code{conf.high}, \code{ipm} ads a \code{column ipm}
@@ -117,22 +104,6 @@
ggplot(aes(year, ipm, fill = condition, color = condition)) +
geom_freq_by_year_ci()
}
-library(ggplot2)
-kco <- new("KorAPConnection", verbose=TRUE)
-\donttest{year <- (2003:2011)}\dontshow{year <- c(2005)}
-\donttest{condition <- c("textDomain = /Wirtschaft.*/", "textDomain != /Wirtschaft.*/")}\dontshow{condition <- c("textDomain = /Wirtschaft.*/")}
-g <- expand_grid(condition, year) \%>\%
- cbind(frequencyQuery(kco, "[tt/l=Heuschrecke]",
- paste0(.$condition," & pubDate in ", .$year))) \%>\%
- ipm() \%>\%
- ggplot(aes(year, ipm, fill = condition, color = condition)) +
- ## theme_light(base_size = 20) +
- geom_freq_by_year_ci()
-p <- ggplotly(g)
-print(p)
-## saveWidget(p, paste0(tmpdir(), "heuschrecke.html")
-
-
}
\seealso{
\code{ci} is already included in \code{\link{frequencyQuery}}
diff --git a/tests/testthat/test-demos.R b/tests/testthat/test-demos.R
index bfc8f2e..8f99284 100644
--- a/tests/testthat/test-demos.R
+++ b/tests/testthat/test-demos.R
@@ -116,27 +116,3 @@
hc_freq_by_year_ci()
expect_true(all(class(hc) %in% c("highchart", "htmlwidget")))
})
-
-test_that("Conditions over time ggplotly example works", {
- kco <- new("KorAPConnection")
- p <- expand_grid(
- condition = c("textDomain = /Wirtschaft.*/",
- "textDomain != /Wirtschaft.*/"),
- year = (2010:2013)
- ) %>%
- cbind(frequencyQuery(
- kco,
- "[tt/l=Heuschrecke]",
- paste(.$condition, "& pubDate in", .$year)
- )) %>%
- ipm() %>%
- ggplot(aes(
- x = year,
- y = ipm,
- fill = condition,
- colour = condition
- )) +
- geom_freq_by_year_ci()
- pp <- ggplotly(p)
- expect_error(print(pp), NA)
-})