Skip to content

Commit 7691396

Browse files
authored
Merge pull request #39 from Appsilon/doc/add-tutorials
[Documentation] Tutorials/how to guides for all features
2 parents 0ef03c9 + 69ba727 commit 7691396

13 files changed

Lines changed: 469 additions & 218 deletions

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Imports:
2020
dplyr,
2121
htmltools,
2222
purrr (>= 1.0.0),
23-
reactable,
23+
reactable (>= 0.4.0),
2424
rjson,
2525
rlang,
2626
shiny

README.md

Lines changed: 52 additions & 216 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,21 @@
55
<!-- badges: start -->
66
[![CRAN status](https://www.r-pkg.org/badges/version/reactable.extras)](https://cran.r-project.org/package=reactable.extras)
77
[![R-CMD-check](https://github.com/Appsilon/reactable.extras/workflows/R-CMD-check/badge.svg)](https://github.com/Appsilon/reactable.extras/actions/workflows/main.yml)
8+
![Codecov test coverage](https://codecov.io/gh/Appsilon/reactable.extras/branch/main/graph/badge.svg)
89
<!-- badges: end -->
910

11+
`reactable.extras` is an R package that enhances the functionality of the [reactable](https://glin.github.io/reactable/) package in Shiny applications. Reactable tables are interactive customizable, and `reactable.extras` extend their capabilities, allowing you to create dynamic and interactive data tables with ease.
12+
13+
In the context of web apps, you often need to provide users with additional tools and interactivity for data exploration. `reactable.extras` address this need by offering a set of functions and components that can be seamlessly integrated into your Shiny apps.
14+
1015
## How to install?
1116

17+
Stable version:
18+
19+
```r
20+
install.packages("reactable.extras")
21+
```
22+
1223
Development version:
1324

1425
```r
@@ -17,237 +28,62 @@ remotes::install_github("Appsilon/reactable.extras")
1728

1829
## How to use it?
1930

20-
### Server-Side Processing
21-
22-
Rendering a `reactable` with a lot of data can be inefficient. The initial loading will take some time, and a lot of memory will be thrown to the browser.
31+
Getting started with `reactable.extras` is straightforward:
2332

24-
A more efficient approach is to render only the data that is needed to be displayed.
25-
26-
`reactable_extras_ui()` and `reactalbe_extras_server()` is a wrapper for `reactable::reactableOutput()` and `reactable::renderReactable({reactable(...)})`.
27-
It renders only a subset of a large data in the server memory. This almost instantly renders the desired page and keeps the amount of memory used in the browser minimal.
28-
29-
Consider this example data:
33+
1. Make sure you have latest version of `{reactable}`. It's required to be at least on version 0.4.0
34+
2. Include the necessary functions and components in your Shiny UI definition.
35+
3. Use the provided functions to enhance your reactable tables. You can add custom buttons, checkboxes, date pickers, dropdowns, and text inputs to your table cells.
36+
4. Customize the behavior and appearance of these input components based on your application's requirements.
37+
5. Implement server-side processing and pagination controls for large datasets.
3038

3139
```r
3240
library(shiny)
3341
library(reactable)
3442
library(reactable.extras)
3543

36-
mtcars_ultra <- purrr::map(
37-
seq(1L, 20000L, by = 1L),
38-
~ {
39-
temp_df <- mtcars
40-
temp_df$make <- rownames(temp_df)
41-
rownames(temp_df) <- NULL
42-
temp_df <-
43-
dplyr::mutate(temp_df, id_row = paste0("id_", dplyr::row_number(), "_", .x))
44-
45-
temp_df
46-
},
47-
.progress = TRUE
48-
) |>
49-
purrr::list_rbind()
50-
```
51-
52-
And compare the difference in initial load time and amount of memory used in the browser when loading all the data at once vs loading only the data needed for the page.
53-
54-
```r
55-
# All of the data rendered all at once
56-
shinyApp(
57-
reactableOutput("test"),
58-
function(input, output, server) {
59-
output$test <- renderReactable(
60-
reactable(
61-
data = mtcars_ultra,
62-
columns = list(
63-
mpg = colDef(name = "Miles per Gallon"),
64-
cyl = colDef(name = "Cylinders"),
65-
disp = colDef(name = "Displacement")
66-
),
67-
defaultPageSize = 16
68-
)
69-
)
70-
}
44+
data <- data.frame(
45+
ID = 1:1000,
46+
SKU_Number = paste0("SKU ", 1:1000),
47+
Actions = rep(c("Updated", "Initialized"), times = 20),
48+
Registered = as.Date("2023/1/1")
7149
)
7250

73-
# Only the subset of the data needed for the page is rendered
74-
shinyApp(
75-
reactable_extras_ui("test"),
76-
function(input, output, server) {
77-
reactable_extras_server(
78-
"test",
79-
data = mtcars_ultra,
80-
columns = list(
81-
mpg = colDef(name = "Miles per Gallon"),
82-
cyl = colDef(name = "Cylinders"),
83-
disp = colDef(name = "Displacement")
84-
),
85-
total_pages = 4e4
86-
)
87-
}
51+
ui <- fluidPage(
52+
# Include reactable.extras in your UI
53+
reactable_extras_dependency(),
54+
reactableOutput("my_table")
8855
)
8956

90-
```
91-
92-
Server-Side Processing | Rendering All Data At Once
93-
:--------------------------------------:|:-----------------------------------:
94-
![](man/figures/server-side-processing.gif) | ![](man/figures/full-data-rendered.gif)
95-
96-
### Custom inputs
97-
98-
You can use custom inputs inside your reactable column.
99-
100-
Supported types for now:
101-
102-
- text input: `text_extra`
103-
- button: `button_extra`
104-
- dropdown: `dropdown_extra`
105-
- date: `date_extra`
106-
- checkbox: `checkbox_extra`
107-
108-
It's possible to apply additional styling to your inputs by passing `class` argument:
109-
110-
`checkbox_extra("check", class = "checkbox-extra")`
111-
112-
Also it's important to import javascript dependencies by adding to `ui`:
113-
114-
`reactable.extras::reactable_extras_dependency()`
115-
116-
All events of your inputs will be tracked and can be used in your shiny server.
117-
118-
Example application:
119-
120-
```r
121-
library(shiny)
122-
library(reactable)
123-
library(reactable.extras)
124-
string_list <- function(values) {
125-
paste0(
126-
"{", paste0(names(values), " : ", unlist(values), collapse = ", "), "}"
127-
)
128-
}
129-
130-
shinyApp(
131-
ui = fluidPage(
132-
reactable.extras::reactable_extras_dependency(),
133-
reactableOutput("react"),
134-
hr(),
135-
textOutput("date_text"),
136-
textOutput("button_text"),
137-
textOutput("check_text"),
138-
textOutput("dropdown_text"),
139-
textOutput("text")
140-
),
141-
server = function(input, output) {
142-
output$react <- renderReactable({
143-
# preparing the test data
144-
df <- MASS::Cars93[, 1:4]
145-
df$Date <- sample(seq(as.Date("2020/01/01"),
146-
as.Date("2023/01/01"),
147-
by = "day"),
148-
nrow(df))
149-
df$Check <- sample(c(TRUE, FALSE), nrow(df), TRUE)
150-
reactable(
151-
df,
152-
columns = list(
153-
Manufacturer = colDef(
154-
cell = button_extra("button", class = "button-extra")
155-
),
156-
Check = colDef(
157-
cell = checkbox_extra("check", class = "checkbox-extra"),
158-
align = "left"
159-
),
160-
Date = colDef(
161-
cell = date_extra("date", class = "date-extra")
162-
),
163-
Type = colDef(
164-
cell = dropdown_extra(
165-
"dropdown",
166-
unique(df$Type),
167-
class = "dropdown-extra"
168-
)
169-
),
170-
Model = colDef(
171-
cell = text_extra(
172-
"text"
173-
)
174-
)
57+
server <- function(input, output, session) {
58+
output$my_table <- renderReactable({
59+
# Create a reactable table with enhanced features
60+
reactable(
61+
data,
62+
columns = list(
63+
ID = colDef(name = "ID"),
64+
SKU_Number = colDef(name = "SKU_Number"),
65+
Actions = colDef(
66+
name = "Actions",
67+
cell = button_extra("button", class = "btn btn-primary")
68+
),
69+
Registered = colDef(
70+
cell = date_extra("Registered", class = "date-extra")
17571
)
17672
)
177-
})
178-
output$date_text <- renderText({
179-
req(input$date)
180-
values <- input$date
181-
paste0(
182-
"Date: ",
183-
string_list(values)
184-
)
185-
})
186-
output$check_text <- renderText({
187-
req(input$check)
188-
values <- input$check
189-
paste0(
190-
"Check: ",
191-
string_list(values)
192-
)
193-
})
194-
output$button_text <- renderText({
195-
req(input$button)
196-
values <- input$button
197-
paste0(
198-
"Button: ",
199-
string_list(values)
200-
)
201-
})
202-
203-
output$dropdown_text <- renderText({
204-
req(input$dropdown)
205-
values <- input$dropdown
206-
paste0(
207-
"Dropdown: ",
208-
string_list(values)
209-
)
210-
})
211-
212-
output$text <- renderText({
213-
req(input$text)
214-
values <- input$text
215-
paste0(
216-
"Dropdown: ",
217-
string_list(values)
218-
)
219-
})
220-
}
221-
)
222-
223-
```
224-
225-
![](man/figures/custom-inputs.gif)
226-
227-
Example of saving the state when changing the page:
228-
229-
```R
230-
# helper function
231-
update_table <- function(data, id, column, value, key_column = NULL) {
232-
if (!is.null(key_column)) {
233-
data[data[[key_column]] == id, column] <- value
234-
} else {
235-
data[id, column] <- value
236-
}
237-
return(data)
73+
)
74+
})
75+
76+
observeEvent(input$button, {
77+
showModal(modalDialog(
78+
title = "Selected row data",
79+
reactable(data[input$button$row, ])
80+
))
81+
})
82+
23883
}
23984

240-
# in server.R
241-
values <- input$text
242-
updateReactable(
243-
"react",
244-
data = update_table(
245-
df,
246-
values$row,
247-
values$column,
248-
values$value
249-
)
250-
)
85+
shinyApp(ui, server)
86+
25187
```
25288

25389
## How to contribute?

inst/WORDLIST

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,6 @@ dropdown
99
htmlDependency
1010
javascript
1111
reactable
12+
customizable
13+
Codecov
14+
tooltips

pkgdown/_pkgdown.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,22 @@ url: https://appsilon.github.io/reactable.extras/
3131
navbar:
3232
bg: primary
3333
structure:
34-
left: [home, reference]
34+
left: [home, tutorials, reference]
3535
right: [search, github, twitter, mastodon]
3636
components:
3737
home:
3838
icon: fa-home
3939
text: "Start"
4040
href: index.html
41+
tutorials:
42+
text: Tutorials
43+
menu:
44+
- text: Server-Side Processing
45+
href: articles/tutorial/server-side-processing.html
46+
- text: Custom inputs
47+
href: articles/tutorial/custom-inputs.html
48+
- text: Combine reactables features
49+
href: articles/tutorial/combine-reactable-features.html
4150
reference:
4251
icon: fa-file-code-o
4352
text: "Reference"

0 commit comments

Comments
 (0)