Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding a vertical and horizontal scroll bar to the DT table in R shiny

Please check the data table "Case Analyses Details" on the right. I want to fit the data table within the box, such that it aligns from right and bottom border in the box, such that we add a horizontal and vertical scroll bar to the DT which can be used to span the rows that overshoot the box.

## app.R ##
library(shiny)
library(shinydashboard)
library(DT)
ui <- dashboardPage(
dashboardHeader(title = "My Chart"),
dashboardSidebar(
width = 0
),
dashboardBody(
box(title = "Data Path", status = "primary",height = "595" ,solidHeader = T,
    plotOutput("trace_plot")),
box( title = "Case Analyses Details", status = "primary", height = 
"595",width = "6",solidHeader = T, 
     div(DT::dataTableOutput("trace_table",width = 220)))
))
server <- function(input, output) 
{ 
#Plot for Trace Explorer
output$trace_plot <- renderPlot({
plot(iris$Sepal.Length,iris$Sepal.Width)
})
output$trace_table <- renderDataTable({
mtcars
})
}
shinyApp(ui, server)

MTCARS CAPTURE

like image 473
Ashmin Kaul Avatar asked Nov 27 '17 07:11

Ashmin Kaul


People also ask

How can use the horizontal and vertical scroll bars to?

You can use the horizontal and vertical scroll bars to view different rows and columns edit the contents of a cell.

How do I make a horizontal scroll in Datatable?

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 .

How do I add a horizontal scrollbar?

To make a scroll box with a horizontal scroll, you need to use the overflow-x property. Specifically, you need to use this code: overflow-x:scroll; . This tells your browser to create scroll bars on the x (horizontal) axis, whenever the contents of the container is too wide.

Can scroll bars be vertical or horizontal?

A horizontal scroll bar enables the user to scroll the content of a window to the left or right. A vertical scroll bar enables the user to scroll the content up or down.

How do I add a vertical scrollbar in HTML?

Suppose we want to add a scroll bar option in HTML, use an “overflow” option and set it as auto-enabled for adding both horizontal and vertical scrollbars. If we want to add a vertical bar option in Html add the line “overflow-y” in the files. CSS File Syntax for Scrollbars

Can DataTables do horizontal and vertical scrolling at the same time?

In this example you can see DataTables doing both horizontal and vertical scrolling at the same time. Note also that pagination is enabled in this example, and the scrolling accounts for this.

How do I access the indices of selected rows in shiny?

By default, the selected rows are highlighted in blue, and within an interactive Shiny app the indices of selected rows can be accessed by using input$tableID_rows_selected in server.R.

How to add vertical bar option in HTML page?

If we want to add a vertical bar option in Html, add the line “overflow-y” in the files. By using the <Style> tag, we will add the scroll options in HTML Page itself. Given are the examples for the HTML table:


1 Answers

Something like this do?

rm(list = ls())
## app.R ##
library(shiny)
library(shinydashboard)
library(DT)
ui <- dashboardPage(
  dashboardHeader(title = "My Chart"),
  dashboardSidebar(
    width = 0
  ),
  dashboardBody(
    box(title = "Data Path", status = "primary",height = "595" ,solidHeader = T,
        plotOutput("trace_plot")),
    box( title = "Case Analyses Details", status = "primary", height = 
           "595",width = "6",solidHeader = T, 
         column(width = 12,
                DT::dataTableOutput("trace_table"),style = "height:500px; overflow-y: scroll;overflow-x: scroll;"
         )
    )))
server <- function(input, output) { 
  #Plot for Trace Explorer
  output$trace_plot <- renderPlot({
    plot(iris$Sepal.Length,iris$Sepal.Width)
  })
  output$trace_table <- renderDataTable({

    datatable(cbind(mtcars,mtcars), options = list(paging = FALSE))

  })
}
shinyApp(ui, server)

enter image description here

like image 199
Pork Chop Avatar answered Oct 22 '22 12:10

Pork Chop