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 2 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
6 changes: 5 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,11 @@
)
),
# Benchmarking table --------------------------------------
dataTableOutput("tabBenchmark")
h2('An example Datatable'),

Check notice

Code scanning / lintr

Only use double-quotes. Note

Only use double-quotes.
dataTableOutput("tabBenchmark"),
Copy link
Contributor

Choose a reason for hiding this comment

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

I think let's just remove the old reference to data table. We're moving towards reactable as we find it easier for to customise.

br(),
h2('An example Reactable'),

Check notice

Code scanning / lintr

Only use double-quotes. Note

Only use double-quotes.
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
83 changes: 56 additions & 27 deletions server.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,17 @@
"plotly_click-A", "plotly_hover-A", "plotly_afterplot-A",
".clientValue-default-plotlyCrosstalkOpts"
))

Check notice

Code scanning / lintr

Trailing whitespace is superfluous. Note

Trailing whitespace is superfluous.
observe({
# Trigger this observer every time an input changes
reactiveValuesToList(input)
session$doBookmark()
})

Check notice

Code scanning / lintr

Trailing whitespace is superfluous. Note

Trailing whitespace is superfluous.
onBookmarked(function(url) {
updateQueryString(url)
})

Check notice

Code scanning / lintr

Trailing whitespace is superfluous. Note

Trailing whitespace is superfluous.
observe({
if (input$navlistPanel == "Example tab 1") {
change_window_title(
Expand All @@ -66,7 +66,7 @@
)
}
})

Check notice

Code scanning / lintr

Trailing whitespace is superfluous. Note

Trailing whitespace is superfluous.
# Cookies logic -------------------------------------------------------------
observeEvent(input$cookies, {
if (!is.null(input$cookies)) {
Expand All @@ -92,7 +92,7 @@
shinyjs::hide(id = "cookieMain")
}
})

Check notice

Code scanning / lintr

Trailing whitespace is superfluous. Note

Trailing whitespace is superfluous.
# Need these set of observeEvent to create a path through the cookie banner
observeEvent(input$cookieAccept, {
msg <- list(
Expand All @@ -104,7 +104,7 @@
shinyjs::show(id = "cookieAcceptDiv")
shinyjs::hide(id = "cookieMain")
})

Check notice

Code scanning / lintr

Trailing whitespace is superfluous. Note

Trailing whitespace is superfluous.
observeEvent(input$cookieReject, {
msg <- list(
name = "dfe_analytics",
Expand All @@ -115,27 +115,27 @@
shinyjs::show(id = "cookieRejectDiv")
shinyjs::hide(id = "cookieMain")
})

Check notice

Code scanning / lintr

Trailing whitespace is superfluous. Note

Trailing whitespace is superfluous.
observeEvent(input$hideAccept, {
shinyjs::toggle(id = "cookieDiv")
})

Check notice

Code scanning / lintr

Trailing whitespace is superfluous. Note

Trailing whitespace is superfluous.
observeEvent(input$hideReject, {
shinyjs::toggle(id = "cookieDiv")
})

Check notice

Code scanning / lintr

Trailing whitespace is superfluous. Note

Trailing whitespace is superfluous.
observeEvent(input$remove, {
shinyjs::toggle(id = "cookieMain")
msg <- list(name = "dfe_analytics", value = "denied")
session$sendCustomMessage("cookie-remove", msg)
session$sendCustomMessage("analytics-consent", msg)
print(input$cookies)
})

Check notice

Code scanning / lintr

Trailing whitespace is superfluous. Note

Trailing whitespace is superfluous.
cookies_data <- reactive({
input$cookies
})

Check notice

Code scanning / lintr

Trailing whitespace is superfluous. Note

Trailing whitespace is superfluous.
output$cookie_status <- renderText({
cookie_text_stem <- "To better understand the reach of our dashboard tools,
this site uses cookies to identify numbers of unique users as part of Google
Expand All @@ -153,23 +153,23 @@
"Cookies consent has not been confirmed."
}
})

Check notice

Code scanning / lintr

Trailing whitespace is superfluous. Note

Trailing whitespace is superfluous.
observeEvent(input$cookieLink, {
# Need to link here to where further info is located. You can
# updateTabsetPanel to have a cookie page for instance
updateTabsetPanel(session, "navlistPanel",
selected = "Support and feedback"
selected = "Support and feedback"

Check notice

Code scanning / lintr

Indentation should be 6 spaces but is 22 spaces. Note

Indentation should be 6 spaces but is 22 spaces.
)
})

Check notice

Code scanning / lintr

Trailing whitespace is superfluous. Note

Trailing whitespace is superfluous.
# Dataset with timeseries data ----------------------------------------------
reactive_rev_bal <- reactive({
df_revbal %>% filter(
area_name == input$selectArea | area_name == "England",
school_phase == input$selectPhase
)
})

Check notice

Code scanning / lintr

Trailing whitespace is superfluous. Note

Trailing whitespace is superfluous.
# Dataset with benchmark data -----------------------------------------------
reactive_benchmark <- reactive({
df_revbal %>%
Expand All @@ -179,7 +179,7 @@
year == max(year)
)
})

Check notice

Code scanning / lintr

Trailing whitespace is superfluous. Note

Trailing whitespace is superfluous.
# Charts --------------------------------------------------------------------
# Line chart for revenue balance over time
output$lineRevBal <- renderGirafe({
Expand All @@ -193,7 +193,7 @@
height_svg = 5.0
)
})

Check notice

Code scanning / lintr

Trailing whitespace is superfluous. Note

Trailing whitespace is superfluous.
# Benchmarking bar chart
output$colBenchmark <- renderGirafe({
girafe(
Expand All @@ -206,7 +206,7 @@
height_svg = 5.0
)
})

Check notice

Code scanning / lintr

Trailing whitespace is superfluous. Note

Trailing whitespace is superfluous.
# Benchmarking table
output$tabBenchmark <- renderDataTable({
Copy link
Contributor

Choose a reason for hiding this comment

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

Again, let's just delete this, the idea is just to replace it with reactable

Copy link
Author

Choose a reason for hiding this comment

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

on it

datatable(
Expand All @@ -223,7 +223,36 @@
)
)
})

Check notice

Code scanning / lintr

Trailing whitespace is superfluous. Note

Trailing whitespace is superfluous.
output$tabBenchmark2 <- renderReactable({
reactable(
reactive_benchmark() %>%
select(
Area = area_name,
`Average Revenue Balance (£)` = average_revenue_balance,
`Total Revenue Balance (£m)` = total_revenue_balance_million
),
# defaultPageSizr and minRows needed for Pagination: example here
# 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)' }
}
}
}")
)
)
})


Check notice

Code scanning / lintr

Trailing whitespace is superfluous. Note

Trailing whitespace is superfluous.
# Value boxes ---------------------------------------------------------------
# Create a reactive value for average revenue balance
latest_average_balance <- reactive({
Expand All @@ -235,7 +264,7 @@
) %>%
pull(average_revenue_balance)
})

Check notice

Code scanning / lintr

Trailing whitespace is superfluous. Note

Trailing whitespace is superfluous.
# Create a reactive value for previous year average
previous_average_balance <- reactive({
previous_year <- reactive_rev_bal() %>%
Expand All @@ -246,13 +275,13 @@
) %>%
pull(average_revenue_balance)
})

Check notice

Code scanning / lintr

Trailing whitespace is superfluous. Note

Trailing whitespace is superfluous.
# Export values for use in UI tests -----------------------------------------
exportTestValues(
avg_rev_bal_value = latest_average_balance(),
prev_avg_rev_bal_value = previous_average_balance()
)

Check notice

Code scanning / lintr

Trailing whitespace is superfluous. Note

Trailing whitespace is superfluous.
# Create a value box for average revenue balance
output$box_balance_latest <- renderValueBox({
value_box(
Expand All @@ -261,7 +290,7 @@
color = "blue"
)
})

Check notice

Code scanning / lintr

Trailing whitespace is superfluous. Note

Trailing whitespace is superfluous.
# Create a value box for the change on previous year
output$box_balance_change <- renderValueBox({
value_box(
Expand All @@ -274,27 +303,27 @@
color = "blue"
)
})

Check notice

Code scanning / lintr

Trailing whitespace is superfluous. Note

Trailing whitespace is superfluous.
# Link in the user guide panel back to the main panel -----------------------
observeEvent(input$link_to_app_content_tab, {
updateTabsetPanel(session, "navlistPanel", selected = "Example tab 1")
})

Check notice

Code scanning / lintr

Trailing whitespace is superfluous. Note

Trailing whitespace is superfluous.
# Download the underlying data button --------------------------------------
output$download_data <- downloadHandler(
filename = "shiny_template_underlying_data.csv",
content = function(file) {
write.csv(df_revbal, file)
}
)

Check notice

Code scanning / lintr

Trailing whitespace is superfluous. Note

Trailing whitespace is superfluous.
# Dynamic label showing custom selections -----------------------------------
output$dropdown_label <- renderText({
paste0("Current selections: ", input$selectPhase, ", ", input$selectArea)
})

Check notice

Code scanning / lintr

Trailing whitespace is superfluous. Note

Trailing whitespace is superfluous.
# Stop app ------------------------------------------------------------------
session$onSessionEnded(function() {
stopApp()
})
}
}

Check notice

Code scanning / lintr

Missing terminal newline. Note

Missing terminal newline.
Loading