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.
install.packages("gotop")
To get a bug fix, or use a feature from the development version, you can install it from GitHub.
# install.packages("remotes")
remotes::install_github("lgnbhl/gotop")
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.
```{r, echo = FALSE}
gotop::use_gotop()
```
To use it in Shiny, call use_gotop()
inside the apps’ UI.
library(shiny)
library(gotop)
shinyApp(
ui = fluidPage(
align = "center",
use_gotop(), # add it inside the ui
h2("Shiny with gotop"),
HTML(rep("↓<br/><br/>scroll down<br/><br/>", 20)),
textOutput("lookright")
),
server = function(input, output, session){
output$lookright <- renderText({ print("Look right") })
}
)
You can replace the default Font Awesome chevron up icon (“fas
fa-chevron-up”) by any other Font Awesome
icon, change its color, width
and much more (run ?use_gotop()
to see the documentation).
gotop::use_gotop(
src = "fas fa-chevron-circle-up", # css class from Font Awesome
color = "tomato", # color
opacity = 0.8, # transparency
width = 30, # size
appear = 100 # number of pixels before appearance
)
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.