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
- From the toolbar, go to Calculation
> Custom Code.
- Click on the Page where you want to position the output.
-
Update and insert the R code below 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) - Click Calculate in the object inspector
.
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 example below uses the BBC UK website and the subsections of the main site.
- From the toolbar, go to Calculation
> Custom Code.
- Click on the Page where you want to position the output.
-
Update and insert the code below 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) - Click Calculate in the object inspector
.
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".