R package to use the Noun Project API
devtools::install_github("CaRdiffR/nounprojectR")
To use this package you need to register with the Noun Project and create an app to get your own key and secret. Copy and paste appname, key and secret and replace in this script:
np_credentials(your_appname, your_key, your_secret)
# This function puts the NounProject details into your enviroment variables.
# Equivalent of that would be to set up and export values for the following variables:
# NOUNS_API_APPNAME, NOUNS_API_KEY, NOUNS_API_SECRET
To display a single icon that you know the index of, use the display_icon
function.
display_icon("1322")
That will open the RStudio Viewer and present you icon number 1322
.
To display many icons based on your query, use display_many_icons
:
display_many_icons("car") # by default there are 4 icons displayed in loop
display_many_icons("car", 6) # displays 6 first icons from the nounproject database
Instead of visiting the Noun Project website all the time, you can use this RStudio addin which will help you to find the icon you are particulalry interested in. By default addin displays 20 most relevant searches for icons with public domain license only.
TO run it, simply go to Addins > Noun Project
in your RStudio.
For more advanced usecases, have a look at some examples below.
# this should download and show the icon of a plane
res <- get_nouns_api("icon/609")
get_png(res)
# this should download and show the icon of four dogs
# make the url
url <- nounprojectR::make_term_endpoint("dog", num_of_imgs = 4)
# hit the Noun Project server
res <- get_nouns_api(url)
# extract the JSON file
result <- httr::content(res)
# show the images
get_pngs_and_show(result)
Please raise issues if you need help or would like to make comments.
We welcome new contributions! Please read our Code of Conduct first.
This project was inspired by the Hacktoberfest 2018. Check out Hacktoberfest GitHub blog and support the event in the following editions.