Skip to content
Closed
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
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ Imports:
ggplot2
URL: https://rstudio.github.io/crosstalk/
BugReports: https://github.com/rstudio/crosstalk/issues
RoxygenNote: 6.1.1
RoxygenNote: 7.1.0
3 changes: 2 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## crosstalk 1.0.1.9000

* Add `selected` parameter to `filter_select`, to specify default selection.
* Add `selected` parameter to `filter_select`, `filter_checkbox`, to
specify default selection.

## crosstalk 1.0.1

Expand Down
19 changes: 13 additions & 6 deletions R/controls.R
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ columnize <- function(columnCount, elements) {
#'
#' @rdname filter_select
#' @export
filter_checkbox <- function(id, label, sharedData, group, allLevels = FALSE, inline = FALSE, columns = 1) {
filter_checkbox <- function(id, label, sharedData, group, allLevels = FALSE, inline = FALSE, columns = 1, selected=NULL) {
options <- makeGroupOptions(sharedData, group, allLevels)

labels <- options$items$label
Expand All @@ -205,7 +205,7 @@ filter_checkbox <- function(id, label, sharedData, group, allLevels = FALSE, inl
tags$div(class = "crosstalk-options-group",
columnize(columns,
mapply(labels, values, FUN = function(label, value) {
makeCheckbox(id, value, label)
makeCheckbox(id, value, label, value %in% selected)
}, SIMPLIFY = FALSE, USE.NAMES = FALSE)
)
),
Expand All @@ -218,18 +218,25 @@ filter_checkbox <- function(id, label, sharedData, group, allLevels = FALSE, inl
))
}

blockCheckbox <- function(id, value, label) {
blockCheckbox <- function(id, value, label, checked) {
ifelse(checked,
cbox <- tags$input(type = "checkbox", name = id, value = value, checked=NA),
cbox <- tags$input(type = "checkbox", name = id, value = value))
tags$div(class = "checkbox",
tags$label(
tags$input(type = "checkbox", name = id, value = value),
cbox,
tags$span(label)
)
)
}

inlineCheckbox <- function(id, value, label) {
inlineCheckbox <- function(id, value, label, checked) {
ifelse(checked,
cbox <- tags$input(type = "checkbox", name = id, value = value, checked=NA),
cbox <- tags$input(type = "checkbox", name = id, value = value))

tags$label(class = "checkbox-inline",
tags$input(type = "checkbox", name = id, value = value),
cbox,
tags$span(label)
)
}
Expand Down
9 changes: 8 additions & 1 deletion inst/www/js/crosstalk.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions inst/www/js/crosstalk.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion inst/www/js/crosstalk.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion inst/www/js/crosstalk.min.js.map

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion javascript/src/input_checkboxgroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ input.register({

let lastKnownKeys;
let $el = $(el);
$el.on("change", "input[type='checkbox']", function() {
function updateFilter() {
let checked = $el.find("input[type='checkbox']:checked");
if (checked.length === 0) {
lastKnownKeys = null;
Expand All @@ -32,6 +32,11 @@ input.register({
lastKnownKeys = keyArray;
ctHandle.set(keyArray);
}
}
$el.on("change", "input[type='checkbox']", updateFilter);
// https://stackoverflow.com/a/2926235/1527747

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
// https://stackoverflow.com/a/2926235/1527747

$(window).on("load", function() {
updateFilter();
});

return {
Expand Down
5 changes: 4 additions & 1 deletion javascript/src/input_selectize.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ input.register({
}
}
selectize.on("change", updateFilter);
updateFilter();
// https://stackoverflow.com/a/2926235/1527747

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
// https://stackoverflow.com/a/2926235/1527747

$(window).on("load", function() {
updateFilter();
});

return {
suspend: function() {
Expand Down
64 changes: 60 additions & 4 deletions man/ClientValue.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

114 changes: 108 additions & 6 deletions man/SharedData.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 19 additions & 4 deletions man/filter_select.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 26 additions & 7 deletions man/filter_slider.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading