-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
220 additions
and
146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ Imports: | |
shinyWidgets | ||
Suggests: | ||
apexcharter, | ||
bslib, | ||
knitr, | ||
rmarkdown, | ||
scales, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
|
||
#' Display buttons in grid's column | ||
#' | ||
#' @param grid A table created with [datagrid()]. | ||
#' @param column The name of the column where to create buttons. | ||
#' @param inputId The `input` slot that will be used to access the value. | ||
#' @param label Label to display on button, if `NULL` use column's content. | ||
#' @param icon Icon to display in button. | ||
#' @param status Bootstrap status (color) of the button: default, primary, success, info, warning, danger, ... | ||
#' A class prefixed by `btn-` will be added to the button. | ||
#' @param btn_width Button's width. | ||
#' @param ... Further arguments passed to [grid_columns()]. | ||
#' | ||
#' @return A `datagrid` htmlwidget. | ||
#' @export | ||
#' | ||
#' @example examples/ex-grid_col_button.R | ||
grid_col_button <- function(grid, | ||
column, | ||
inputId, | ||
label = NULL, | ||
icon = NULL, | ||
status = "default", | ||
btn_width = "100%", | ||
...) { | ||
check_grid(grid, "grid_col_button") | ||
stopifnot(is.character(status)) | ||
stopifnot(is.character(column) & length(column) == 1) | ||
column <- check_grid_column(grid, column) | ||
if (!is.null(icon)) { | ||
icon_deps <- htmltools::findDependencies(icon) | ||
grid$dependencies <- c( | ||
grid$dependencies, | ||
icon_deps | ||
) | ||
icon <- htmltools::doRenderTags(icon) | ||
} | ||
grid_columns( | ||
grid = grid, | ||
columns = column, | ||
..., | ||
renderer = list( | ||
type = JS("datagrid.renderer.button"), | ||
options = dropNulls(list( | ||
status = status[1], | ||
width = btn_width, | ||
label = label, | ||
inputId = inputId, | ||
icon = icon | ||
)) | ||
) | ||
) | ||
} | ||
|
||
|
||
|
||
#' Display checkboxes in grid's column | ||
#' | ||
#' @param grid A table created with [datagrid()]. | ||
#' @param column The name of the column where to create buttons. | ||
#' @param class CSS classes to add to checkbox container. | ||
#' @param ... Further arguments passed to [grid_columns()]. | ||
#' | ||
#' @return A `datagrid` htmlwidget. | ||
#' @export | ||
#' | ||
#' @example examples/ex-grid_col_checkbox.R | ||
grid_col_checkbox <- function(grid, | ||
column, | ||
class = "form-check d-flex justify-content-center my-1", | ||
...) { | ||
check_grid(grid, "grid_col_checkbox") | ||
stopifnot(is.character(column) & length(column) == 1) | ||
column <- check_grid_column(grid, column) | ||
grid_columns( | ||
grid = grid, | ||
columns = column, | ||
..., | ||
renderer = list( | ||
type = JS("datagrid.renderer.checkbox"), | ||
options = dropNulls(list( | ||
class = class | ||
)) | ||
) | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
|
||
library(toastui) | ||
library(shiny) | ||
library(bslib) | ||
|
||
ui <- fluidPage( | ||
theme = bslib::bs_theme(version = 5L), | ||
tags$h2("Checkbox column grid demo"), | ||
fluidRow( | ||
column( | ||
width = 8, | ||
datagridOutput("grid"), | ||
verbatimTextOutput("edited") | ||
) | ||
) | ||
) | ||
|
||
server <- function(input, output, session) { | ||
|
||
output$grid <- renderDatagrid({ | ||
data.frame( | ||
month = month.name, | ||
checkboxes = sample(c(TRUE, FALSE), 12, replace = TRUE), | ||
switches = sample(c(TRUE, FALSE), 12, replace = TRUE) | ||
) %>% | ||
datagrid(data_as_input = TRUE) %>% | ||
grid_col_checkbox(column = "checkboxes") %>% | ||
grid_col_checkbox( | ||
column = "switches", | ||
# /!\ will only works with bslib::bs_theme(version = 5L) | ||
class = "form-check form-switch d-flex justify-content-center my-1" | ||
) | ||
|
||
}) | ||
|
||
output$edited <- renderPrint({ | ||
input$grid_data # outputId + "_data | ||
}) | ||
|
||
} | ||
|
||
if (interactive()) | ||
shinyApp(ui, server) | ||
|
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.