Data Table Output not scrollable in Y direction
Asked Answered
O

4

8

I have data I wish to show in a flexdashboard in R. I build the datatable with DT::renderDataTable({DT::datatable(data(), options=list(scrollX=TRUE))})

This works just fine when showing something like 10 entries, but when I select the option to show 25 entries, I cannot scroll down to the bottom of the page and click on the second page button, next button, etc. I cannot scroll vertically like I could previously. I have tried the sScrollY = "300px" options, but this doesn't let the data table expand to fill the full page on my flexdashboard. The problem is rows of observations being cut off and inaccessible when I try to scroll in the y-direction.

I am wondering what I need to do to make datatables expand and fill as expected, as shown in https://shiny.rstudio.com/gallery/datatables-options.html

From the example, you can see how it is still possible to scroll up and down when you change the number of rows shown. I cannot do this in the new version of datatable. As of right now, I am limiting the number of rows displayed to 10...however, this is not a long term solution.

Any ideas are greatly appreciated. Thank you. Best, NF

Octa answered 23/1, 2017 at 19:42 Comment(1)
Have a look at ScrollerextensionBarehanded
O
4

I haven't been able to find a solution I am satisfied with yet, but for the interim, I am using the sScrollY = '75vh' arguement and building the datatable like this:

DT::renderDataTable({ DT::datatable(plot_data(), options = list(scrollX = TRUE, sScrollY = '75vh', scrollCollapse = TRUE), extensions = list("Scroller")) })

At least this way the pagination is visible. If anyone has additional ideas, I'd love to hear them. Cheers for now. --Nate

Octa answered 24/1, 2017 at 16:33 Comment(1)
This should be the default for datatable(); the ability to scroll shouldn't require addons IMO.Renell
N
1

I had the same problem, I could'nt make datatables expand. The problem was that all the datatables have the option autoWidth = FALSE by default, so you need to change that to autoWidth = TRUE.

Try something like this:

DT::renderDataTable({DT::datatable(data(), options=list(autoWidth = TRUE,scrollX=TRUE))})

After that you should fine with the Width manipulation.

Here is an example.

  library(shiny)
  library(shinydashboard)
  library(DT)

  ui <- dashboardPage(
  dashboardHeader(title="Data Table"),
  dashboardSidebar(
    menuItem(text="Menu",icon=icon("bars"),
             menuSubItem(text="Show datatable",tabName="ShowData", icon=icon("search")))
  ),
  dashboardBody(
    tabItems(
      tabItem(tabName="ShowData",
              box(DT::dataTableOutput("Data"),width = 12)))))

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

  output$Data<-DT::renderDataTable({DT::datatable(data(),options = list(autoWidth = TRUE,scrollX = TRUE))})
})

shinyApp(ui = ui, server = server)
Node answered 23/1, 2017 at 21:17 Comment(2)
Thank you for responding, but the problem isn't anything with working in the x-direction...it's 100% a problem with the y-direction. As soon as I try to select "show 25 rows" I can only see the first 18, and cannot scroll DOWN on the dashboard page to 1. see the remaining observations 2. see the next page icon 3. see the previous/next icon.Octa
Didn't work for me.Renell
L
1

Thanks for reporting this. As I've answered at rstudio/DT#818, the issue can be resolved by adding an option fillContainer = TRUE to DT::datatable().

I mean changing the chunck like below will be enough.


### renderDataTable (reactive)

```{r}

DT::renderDataTable(datatable(mydataset(), rownames = TRUE,
                              options = list(bPaginate = FALSE, searching = FALSE, info = FALSE),
                              fillContainer = TRUE))
```

The reason that using static data(DT::datatable()) works is fillContainer will be enabled by FlexDashBoard. However, under shiny mode, this feature fails to perform.

Louvain answered 6/10, 2020 at 13:22 Comment(2)
Thank you for reporting this and getting back to me.Octa
fillContainer = TRUE didn't fix it for me. Seemed to make no difference.Burrows
P
0

You may use: option = list(scrollY = 300, scrollCollapse = TRUE). I tried this in R Notebook and it works for me.

Pollute answered 7/7, 2020 at 13:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.