In Displayr you can add links to objects and text allowing the user to jump to a different page within your Document (Dashboard), or to a URL outside the Document. This can be time-consuming when creating a large number of links.
Requirements
- List of links in the form of the complete URL address, including the protocol (e.g., http, https, FTP, or mailto).
- Dynamically created list of URLs and their subdomains.
Method - Creating multiple links
- Go to Calculation > Custom Code.
- Click on the Page where you want to position the output.
- Update and insert the below R code in the R Code editor. You will need to update the links and the corresponding link_text_to_show:
## Enter the list of links here
links = c("https://displayr.com",
"https://www.google.com/",
"https://www.youtube.com/",
"https://www.amazon.com",
"https://bbc.co.uk ")
## Enter the labels you want to show instead of the URL itself
link_text_to_show = c("Displayr",
"Google",
"YouTube",
"Amazon",
"BBC UK")
## Create the content for the body of the html which is a list of link using the <a> tag
contents = paste('<a href="', links,'" target="_blank">', link_text_to_show, '</a>', collapse="</br>")
## Combine contents with other HTML and render using rhtmlMetro
your.html = paste('<DOCTYPE html><html><head></head><body>', contents, '</body></html>', sep="")
rhtmlMetro::Box(text = your.html, text.as.html = TRUE) - Select Calculate.
Method - Creating dynamic subdomains
Some websites are databases. That often means that each page on the website in question can be identified by a section of the URL. The below example uses the BBC UK website and the subsections of the main site.
- Go to Calculation > Custom Code.
- Click on the Page where you want to position the output.
- Update and insert the below R code in the R Code editor. You will need to update the base_link and the corresponding links sub-domains.:
## Enter the list of links here
base_link = "https://bbc.co.uk/"
## Enter the labels you want to show instead of the URL itself
links = c("news",
"sports",
"weather",
"iPlayer",
"sounds")
## Create the content for the body of the html which is a list of link using the <a> tag
contents = paste('<a href="', base_link, links,'" target="_blank">', links, '</a>', collapse="</br>")
## Combine contents with other HTML and render using rhtmlMetro
your.html = paste('<!DOCTYPE html><html><head></head><body>', contents, '</body></html>', sep="")
rhtmlMetro::Box(text = your.html, text.as.html = TRUE) - Select Calculate.
Technical Notes
If you'd like the link to open up in the current tab of your dashboard, you can replace the target="_blank" in the code above with target="_parent".