Add a “scroll to top” icon to R Markdown and Shiny

Add a “scroll back to top” Font Awesome icon to R Markdown documents and Shiny using GoTop.


Install the released version from CRAN.

To get a bug fix, or use a feature from the development version, you can install it from GitHub.

R Markdown

To add a scroll up icon in a R Markdown document, simply add use_gotop() inside a R code chunk with {r, echo = FALSE} so the code will not be shown in the final document.


To use it in Shiny, call use_gotop() inside the apps’ UI.


  ui = fluidPage(
    align = "center",
    use_gotop(), # add it inside the ui
    h2("Shiny with gotop"), 
    HTML(rep("&darr;<br/><br/>scroll down<br/><br/>", 20)),
  server = function(input, output, session){
    output$lookright <- renderText({ print("Look right") })

Customize it

You can replace the default Font Awesome icon “fas fa-chevron-up” by any other Font Awesome icon, change its color, width and much more (see arguments of use_gotop() ).