7

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

nate
  • 1,172
  • 1
  • 11
  • 26

4 Answers4

3

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

nate
  • 1,172
  • 1
  • 11
  • 26
  • This should be the default for `datatable()`; the ability to scroll shouldn't require addons IMO. – dss Aug 18 '22 at 03:41
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)
Berris
  • 36
  • 4
  • 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. – nate Jan 23 '17 at 22:08
  • Didn't work for me. – dss Aug 18 '22 at 03:40
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.

Shrek Tan
  • 2,793
  • 8
  • 14
0

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

Ong K.S
  • 229
  • 1
  • 4
  • 15