Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reactable example #107

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion R/ui_panels/example_tab_1.R
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ example_tab_1_panel <- function() {
)
),
# Benchmarking table --------------------------------------
dataTableOutput("tabBenchmark")
h2("An example Reactable"),
reactableOutput("tabBenchmark2")
)
)
)
Expand Down
1 change: 1 addition & 0 deletions global.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ shhh(library(shinyGovstyle))
# Creating charts and tables
shhh(library(ggplot2))
shhh(library(DT))
shhh(library(reactable))

# Data and string manipulation
shhh(library(dplyr))
Expand Down
25 changes: 25 additions & 0 deletions renv.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1204,6 +1204,31 @@
],
"Hash": "5e3c5dc0b071b21fa128676560dbe94d"
},
"reactR": {
"Package": "reactR",
"Version": "0.6.1",
"Source": "Repository",
"Repository": "CRAN",
"Requirements": [
"htmltools"
],
"Hash": "b8e3d93f508045812f47136c7c44c251"
},
"reactable": {
"Package": "reactable",
"Version": "0.4.4",
"Source": "Repository",
"Repository": "CRAN",
"Requirements": [
"R",
"digest",
"htmltools",
"htmlwidgets",
"jsonlite",
"reactR"
],
"Hash": "6069eb2a6597963eae0605c1875ff14c"
},
"rematch2": {
"Package": "rematch2",
"Version": "2.1.2",
Expand Down
26 changes: 19 additions & 7 deletions server.R
Original file line number Diff line number Diff line change
Expand Up @@ -124,23 +124,35 @@
)
})

# Benchmarking table
output$tabBenchmark <- renderDataTable({
datatable(
output$tabBenchmark2 <- renderReactable({
reactable(
reactive_benchmark() %>%
select(
Area = area_name,
`Average Revenue Balance (£)` = average_revenue_balance,
`Total Revenue Balance (£m)` = total_revenue_balance_million
),
options = list(
scrollX = TRUE,
paging = FALSE,
searching = FALSE
# defaultPageSize and minRows needed for Pagination: example here
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's avoid the commented out code. Just have it active (with some relatively appropriate values) and analysts can remove it if needed.

I'd also like to have highlight activated similarly to this table here:
https://github.com/dfe-analytical-services/local-authority-interactive-tool/blob/9f7aa4d06969614f55b002b50502a514d3c1d320/R/fn_table_helpers.R#L227

And then let's set an initial styling so we've got a starting point for editing the css as and when we come to that as well, e.g.:

headerClass = "bar-sort-header",

# defaultPageSize = 4,

Check notice

Code scanning / lintr

Commented code should be removed. Note

Commented code should be removed.
# minRows = 4,

Check notice

Code scanning / lintr

Commented code should be removed. Note

Commented code should be removed.
# searchable = TRUE, # uncomment line if you want a search box
# filterable = TRUE, # uncomment line if you want filters at the top
# filters on individual columns also possible
defaultSorted = list("Total Revenue Balance (£m)" = "desc"),
defaultColDef = colDef(
style = JS("function(rowInfo, column, state) {
// Highlight sorted columns
for (let i = 0; i < state.sorted.length; i++) {
if (state.sorted[i].id === column.id) {
return { background: 'rgba(0, 0, 0, 0.03)' }
}
}
}")
)
)
})


# Value boxes ---------------------------------------------------------------
# Create a reactive value for average revenue balance
latest_average_balance <- reactive({
Expand Down
48 changes: 48 additions & 0 deletions www/dfe_shiny_gov_style.css
Original file line number Diff line number Diff line change
Expand Up @@ -409,4 +409,52 @@ html {
.small-box.bg-dark-blue {
background-color: #12436D !important;
color: #ffffff !important;
}

/* Set default reactable styles */
.reactable {
font-size: 1rem !important;
table-layout: fixed;
width: 100% !important;
word-break: keep-all; /* Prevents breaking words mid-word */
white-space: normal; /* Allows line breaks between words */
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initial css to back up the change requested in the reactable in server.R

Suggested change
.bar-sort-header:hover,
.bar-sort-header:focus {
background: #fd0;
}
/* Add a top bar on ascending sort */
.bar-sort-header[aria-sort="ascending"] {
box-shadow: inset 0 0.188rem 0 0 #1d70b8;
}
/* Add a bottom bar on descending sort */
.bar-sort-header[aria-sort="descending"] {
box-shadow: inset 0 -0.188rem 0 0 #1d70b8;
}
/* Add an animation when toggling between ascending and descending sort */
.bar-sort-header {
transition: box-shadow 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
/* Table row highlighting -------------------------------------------------- */
.rt-tr-highlight:hover {
background-color: #fd0;
}

@media screen and (min-width: 1440px) {
.bslib-sidebar-layout .sidebar-title {
font-size: 1.188rem !important; /* Slightly larger font size for large monitors */
}
}

@media screen and (min-width: 1240px) {
.bslib-sidebar-layout .sidebar-title {
font-size: 1.1rem !important; /* Slightly larger font size for large laptops */
}
}

/* Media query for laptop screens (1024px or smaller) */
@media screen and (max-width: 1024px) {
.reactable,
.bslib-sidebar-layout > .sidebar > .sidebar-content label,
.selectize-control.multi .selectize-input.has-items {
font-size: 0.9rem !important; /* Slightly smaller font size for laptops */
}
}

/* Media query for tablet-sized screens (768px or smaller) */
@media screen and (max-width: 768px) {
.reactable,
.bslib-sidebar-layout > .sidebar > .sidebar-content label,
.selectize-control.multi .selectize-input.has-items {
font-size: 0.8rem !important; /* Smaller font size for tablets */
}
}

/* Media query for small screens (480px or smaller) */
@media screen and (max-width: 480px) {
.reactable,
.bslib-sidebar-layout > .sidebar > .sidebar-content label,
.selectize-control.multi .selectize-input.has-items {
font-size: 0.7rem !important; /* Even smaller font size for mobile */
}
}
Loading