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
DataTables has the ability to show tables with horizontal scrolling, which is very useful for when you have a wide table, but want to constrain it to a limited horizontal display area. To enable x-scrolling simply set the scrollX parameter to be true .
The approach of this article is to create table with 100% width using width property and create vertical scroll inside table body using overflow-y property. Overflow property is used to create scrollbar in table. Use display: block; property to display the block level element.
The DataTable also exposes a powerful API that can be further used to modify how the data is displayed. The scrollCollapse option is used to specify whether the table will collapse when the scrollY option is used to determine the maximum height of the table.
With the Expanded widget we take the available space in the row. With the SingleChildScrollView we make it scrollable by setting the scrollDirection to Axis. Horizontal. With this table we will display the rest of the data.
The scrollY option is used to specify whether vertical scrolling should be enabled in a DataTable. This option will restrict the height of the DataTable to the given value and allow the user to scroll any overflowing content in the table itself. This can be used in situations where multiple tables need to be fit in a limited space.
If a DataTable is configured with scrollableof "y", but the widthattribute is also set, DataTable will attempt to make the table that wide. But if the table data doesn't fit within the configured width, the table will expand naturally to fit the data.
The scrollY option is used to specify whether vertical scrolling should be enabled in a DataTable. This option will restrict the height of the DataTable to the given value and allow the user to scroll any overflowing content in the table itself.
The DataTable also exposes a powerful API that can be further used to modify how the data is displayed. The scrollY option is used to specify whether vertical scrolling should be enabled in a DataTable. This option will restrict the height of the DataTable to the given value and allow the user to scroll any overflowing content in the table itself.
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
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With