3

I am programming a larger shiny interface, with an ui.r mainPanel containing a tabsetPanel with several tabPanels and within each such different kinds of table and plot outputs. It looks great, except that pages which need to be scrolled tend to jump in their scrolling positions upon, e.g., (re)selecting plot outputs, table entries, etc. Jumps sometimes go to the beginning of the page, sometimes elsewhere; they arise in both Firefox and Chrome. Thus, is there any way to prevent or suppress such jumping? Thank you very much for your help.

Below is a minimal example, in which the ui jumps to the top of the page after a selection is made in the table rows at the bottom of the page:

library(shiny)
library(DT)
data=data.frame(x=1:10,y=2:11)

ui=shinyUI(
  fluidPage(
    plotOutput("plot1"),
    plotOutput("plot2"),
    DT::dataTableOutput("tt")
  )
)

server=shinyServer(function(input, output) {
  dd=reactiveValues(d=data)
  output$plot1 <- renderPlot({plot(0,1)})
  output$plot2 <- renderPlot({plot(0,1)}) 
  output$tt=DT::renderDataTable(
    datatable(
      dd$d,selection =c('single')
    )
  )
  observeEvent(input$tt_rows_selected,{
    dd$d[input$tt_rows_selected,1]<-log(dd$d[input$tt_rows_selected,1])
  })
})

shinyApp(ui,server)
martin
  • 785
  • 5
  • 17
  • Could you include some example code? I'm not really understanding your question and providing a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) would be very helpful. – Chase Grimm Jun 21 '16 at 17:39
  • 1
    Sure, added that above. – martin Jun 24 '16 at 15:16

1 Answers1

0
library(shiny)
library(DT)
data=data.frame(x=1:10,y=2:11)

ui=shinyUI(
  fluidPage(
    plotOutput("plot1"),
    plotOutput("plot2"),
    DT::dataTableOutput("tt")
  )
)

server=shinyServer(function(input, output) {
  dd=reactiveValues(d=data)
  output$plot1 <- renderPlot({plot(0,1)})
  output$plot2 <- renderPlot({plot(0,1)}) 
  output$tt=DT::renderDataTable(
    datatable(
      data,selection ='single'
    )
  )
  observeEvent(input$tt_rows_selected,{
    dd$d[input$tt_rows_selected,1]<-log(dd$d[input$tt_rows_selected,1])
  })
})

shinyApp(ui,server)

This works for me. The problem was the selection = c('single'). It should be selection = 'single'. In the documentation for DT::datatable the arguments you can pass to selection are contained in c() just to indicate what all the options are.

Chase Grimm
  • 417
  • 3
  • 14
  • 1
    Thank. But no - that does not work; in your example, you replaced dd$d in renderDataTable by data. This makes the observeEvent for _rows_selected obsolete. No responsive row selection, no jumping - in whatever way "single" might be defined. You may consider removing your example from this post, maybe? – martin Jun 27 '16 at 10:33