library("shutterstock") knitr::opts_chunk$set( eval = FALSE, collapse = TRUE, comment = "##", fig.path = "man/figures/README-", out.width = "100%" )
R package for Shutterstock REST API. Please refer to the official reference here.
You can install the released version of shutterstock package from CRAN with:
install.packages("shutterstock")
You can install the development version:
# install.packages("devtools") devtools::install_github("strboul/shutterstock")
Search the most popular images about Amsterdam:
library("shutterstock") amsterdam <- searchImages(query = "Amsterdam", sort = "popular") d <- amsterdam[["data"]] do.call(rbind, lapply(d, function(x) { data.frame( id = x[["id"]], description = paste(strtrim(x[["description"]], 35L), "..."), # truncate description field preview = x[["assets"]][["preview"]][["url"]], stringsAsFactors = FALSE ) })) -> popular head(popular)
Build a frequency plot from keywords of the images searched with a family query:
library("ggplot2") images <- searchImages(query = "family", per_page = 225) # extract image ids: image.ids <- sapply(seq_along(images[["data"]]), function(i) { images[["data"]][[i]][["id"]] }) data <- lapply(image.ids, function(x) { cat(sprintf("[%s] get image: \"%s\"", match(x, image.ids), x), sep = "\n") Sys.sleep(4) # try to prevent HTTP 429 error details <- getImageDetails(id = x) as.character(details[["keywords"]]) }) kws <- do.call(c, data) tbl.counts <- as.data.frame(table(kws)) top.tbl <- tbl.counts[order(tbl.counts["Freq"], decreasing = TRUE), ] top <- head(top.tbl, 15L) ggplot(top, aes(x = kws, y = Freq)) + geom_bar(stat = "identity", width = 0.7, color = "black", fill = "white") + labs(title = "The most popular family keywords", x = "Keyword") + ylab(NULL) + theme_bw()
library("ggplot2") # use pre-computed data for easy demonstration: top <- structure(list(kws = c("family", "father", "people", "mother", "happy", "child", "together", "girl", "daughter", "man", "woman", "young", "fun", "lifestyle", "boy"), Freq = c(212L, 191L, 190L, 188L, 183L, 174L, 161L, 155L, 148L, 146L, 145L, 134L, 131L, 117L, 113L)), row.names = c(493L, 515L, 1064L, 973L, 660L, 271L, 1452L, 601L, 377L, 921L, 1587L, 1600L, 578L, 861L, 187L), class = "data.frame") # the same plot as above: ggplot(top, aes(x = kws, y = Freq)) + geom_bar(stat = "identity", width = 0.7, color = "black", fill = "white") + labs(title = "The most popular family keywords", x = "Keyword") + ylab(NULL) + theme_bw()
OAuth 2.0 authentication is better to use for the queries because its scope is greater than the capabilities of the basic authentication. Read the vignette for more information. For general OAuth problems, please read the Shutterstock OAuth 2.0 guide thoroughly.
PRs are welcomed!
Only GET
methods are supported in the current version.
See ?shutterstock
package documentation for more information.
Please note that the shutterstock project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.