add a scrollbar to a box in shiny
Asked Answered
S

2

9

I have implemented a box on R shiny dashboard page using box() function, it loads the table and represents a column full of population numbers. However the numbers overshoot the table and it looks very bad. I wish to add a scrollbar to the box such that the data remains within the box and I can scroll down easily.

box( title = "Btest", status = "primary",height = 355, solidHeader = T, 
                              tableOutput("table1"))
Spidery answered 4/8, 2017 at 4:59 Comment(0)
H
7

you can use library(DT).It provides an R interface to the JavaScript library DataTables. R data objects (matrices or data frames) can be displayed as tables on HTML pages, and DataTables provides filtering, pagination, sorting, and many other features in the tables.

your code will be looks like:

ui.r:

box(
title = "View Data", 
width = NULL,
status = "primary", 
solidHeader = TRUE,
collapsible = TRUE,
div(style = 'overflow-x: scroll', DT::dataTableOutput('view_data'))
     )

In server.r

view_data_fun<-eventreactive/reactive/observe/observeevent({

#your table generation code

  })

output$view_data<-DT::renderDataTable({
    DT::datatable(view_data_fun(),rownames = FALSE)%>%formatStyle(columns=colnames(view_selected_data_fun()),background = 'white',color='black')
  })

you can change the option in %>%formatstyle. for more read DT information

Hobnob answered 4/8, 2017 at 6:59 Comment(3)
Thank you Subhasish, I am able to display my data well now.Spidery
@Subhasish where is this view_selected_data_fun() coming fromPalla
@AnalyticsTeam This is a custom function that i have used for display few columns from a long column list..if you required I can post full code..Hobnob
P
6

Just adding the HTML style option should work!

 box( title = "Btest", status = "primary",height = 355, solidHeader = T, 
                                  tableOutput("table1"), style = "overflow-x: scroll")
Pentomic answered 8/8, 2022 at 19:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.