Skip to content
Scroll to an element in Shiny
R JavaScript
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
R correct block argument Feb 10, 2020
inst/assets
man
.DS_Store init Jan 22, 2020
.Rbuildignore
.gitignore
DESCRIPTION
LICENSE
LICENSE.md
NAMESPACE init Jan 22, 2020
README.md

README.md

shinyscroll

Programatically scroll in Shiny.

Installation

Install it with remotes from Github:

# install.packages("remotes")
remotes::install_github("JohnCoene/shinyscroll")

Example

{shinyscroll} was created to solve the use case below, where I want the window to scroll to a plot dynamically created by a click in a DT table.

library(DT)
library(shiny)
library(shinyscroll)

ui <- fluidPage(
  use_shinyscroll(),
  h1("shinyscroll"),
  p("Select a row"),
  DTOutput("table"),
  plotOutput("plot")
)

server <- function(input, output, session){

  output$table <- renderDT({
    datatable(cars, selection = "single", options = list(pageLength = 20L))
  })

  dataset <- eventReactive(input$table_rows_selected, {
    scroll("plot") # scroll to plot
    runif(100)
  })

  output$plot <- renderPlot(plot(dataset()))
}

shinyApp(ui, server)

It's also used in the DXY tab of the coronavirus tracker

You can’t perform that action at this time.