Skip to content

Instantly share code, notes, and snippets.

@briandconnelly
Last active November 13, 2021 23:56
Show Gist options
  • Save briandconnelly/0435bf83a0abc7df59da0631d80504ed to your computer and use it in GitHub Desktop.
Save briandconnelly/0435bf83a0abc7df59da0631d80504ed to your computer and use it in GitHub Desktop.
Send a push notification with a message and a ggplot2 object

Send a push notification with a message and a ggplot2 object

ggpushover() allows you to send a push notification to your device that contains a message and a ggplot2 object as an image.

Prerequisites

You will need to have the pushoverr and ggplot2 packages installed. To do this, run:

install.packages(c("pushoverr", "ggplot2"))

Demo

library(ggplot2)

p <- ggplot(mtcars, aes(wt, mpg)) + geom_point()
ggpushover(plot = p, message = "We're gonna need a lighter car!")

ggpushover will default to using the plot that has most recently been created or modified, so the command above could be simplified:

ggpushover(message = "We're gonna need a lighter car!")

You can also specify additional things like message title and priority. See ?pushover for more details.

ggpushover <- function(plot = ggplot2::last_plot(),
message,
...) {
rlang::check_installed(pkg = c("pushoverr", "ggplot2"))
stopifnot("ggplot" %in% class(p))
tmpfile <- tempfile(fileext = ".png")
ggplot2::ggsave(filename = tmpfile, plot = plot)
result <- pushoverr::pushover(
message = message,
attachment = tmpfile,
...
)
unlink(tmpfile)
invisible(result)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment