Skip to content

Commit

Permalink
cleaning up package for cmd check
Browse files Browse the repository at this point in the history
  • Loading branch information
dgkf committed Jul 12, 2022
1 parent d03c39f commit 4e95eae
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 37 deletions.
3 changes: 2 additions & 1 deletion .Rbuildignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
^.*\.Rproj$
^\.Rproj\.user$
^\assets
^assets
^README\.Rmd$
^LICENSE\.md$
^\.github$
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,5 @@ importFrom(shiny,wellPanel)
importFrom(stats,density)
importFrom(utils,capture.output)
importFrom(utils,head)
importFrom(utils,methods)
importFrom(utils,tail)
74 changes: 39 additions & 35 deletions R/selectInput_proportion.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,42 +7,46 @@
#' @param ... passed to \code{\link[shiny]{selectizeInput}}
#' @param placeholder passed to \code{\link[shiny]{selectizeInput}} options
#' @param onInitialize passed to \code{\link[shiny]{selectizeInput}} options
#' @param sort how to sort fields in dropdown
#' @param sort how to sort fields in dropdown
#'
#' @return a \code{\link[shiny]{selectizeInput}} dropdown element
#'
#'
#' @importFrom shiny selectizeInput
#'
proportionSelectInput <- function(inputId, label, vec, selected = "", ...,
#'
proportionSelectInput <- function(inputId, label, vec, selected = "", ...,
placeholder = "", onInitialize, sort = c("count", "alpha", "order")) {

sort <- match.arg(sort, c("count", "alpha", "order"), several.ok = FALSE)

vecr <- if (is.reactive(vec)) vec else reactive(vec)

vecr_counts <- sort(table(vecr()), decreasing = TRUE)
vecr_counts <- setNames(as.numeric(vecr_counts), names(vecr_counts))
vecr_names <- names(vecr_counts)
vecr_counts <- as.numeric(vecr_counts)
names(vecr_counts) <- vecr_names
vecr_props <- vecr_counts / sum(vecr_counts)

if (sort == "count") {
vecr_unique <- names(vecr_counts)
} else if (sort == "alpha") {
vecr_unique <- as.character(sort(unique(Filter(Negate(is.na), vecr()))))
} else {
vecr_unique <- unique(Filter(Negate(is.na), vecr()))
}

labels <- Map(function(v) {
json <- sprintf(strip_leading_ws('
{
"name": "%s",
"prop": %f,
"count": %d
}'),
}'),
v, vecr_props[[v]], vecr_counts[[v]])
}, vecr_unique)
choices <- setNames(as.list(vecr_unique), labels)


choices <- as.list(vecr_unique)
names(choices) <- labels

shiny::selectizeInput(
inputId = inputId,
label = label,
Expand All @@ -55,52 +59,52 @@ proportionSelectInput <- function(inputId, label, vec, selected = "", ...,
option: function(item, escape) {
item.data = JSON.parse(item.label);
return '<div style=\"position: relative;\">' +
'<div style=\"position: absolute; top: 5%; bottom: 5%; left: 0%; width: ' + item.data.prop * 100 + '%; background-color: #428BCA; opacity: 0.2;\"></div>' +
'<div style=\"z-index: 1;\">' +
escape(item.data.name) + ' ' +
'<strong style=\"opacity: 0.3;\">' + escape(item.data.count) + '</strong>' +
'</div>' +
'<div style=\"position: absolute; top: 5%; bottom: 5%; left: 0%; width: ' + item.data.prop * 100 + '%; background-color: #428BCA; opacity: 0.2;\"></div>' +
'<div style=\"z-index: 1;\">' +
escape(item.data.name) + ' ' +
'<strong style=\"opacity: 0.3;\">' + escape(item.data.count) + '</strong>' +
'</div>' +
'</div>';
},
// avoid data vomit splashing on screen when an option is selected
item: function(item, escape) {
item: function(item, escape) {
item.data = JSON.parse(item.label);
return '<div style=\"padding-left: 0.5em; padding-right: 0.5em;\">' +
escape(item.value) + ' ' +
'<strong style=\"opacity: 0.3;\">' +
'(' + escape(item.data.count) + ')' +
'</strong>' +
'</div>';
return '<div style=\"padding-left: 0.5em; padding-right: 0.5em;\">' +
escape(item.value) + ' ' +
'<strong style=\"opacity: 0.3;\">' +
'(' + escape(item.data.count) + ')' +
'</strong>' +
'</div>';
}
}")),

# fix for highlight persisting
# https://github.com/selectize/selectize.js/issues/1141
list(onType = I("function(str) {
list(onType = I("function(str) {
str || this.$dropdown_content.removeHighlight();
}")),
list(onChange = I("function() {

list(onChange = I("function() {
this.$dropdown_content.removeHighlight();
}")),

# remove highlighting when losing focus
list(onDropdownOpen = I("function(dropdown) {
dropdown.removeHighlight();
}")),

# placeholder
if (missing(placeholder)) list()
if (missing(placeholder)) list()
else list(placeholder = placeholder),

# onInitialize
if (missing(onInitialize) && !missing(placeholder))
list(onInitialize = I('function() { this.setValue(""); }'))
else if (!missing(onInitialize))
else if (!missing(onInitialize))
list(onInitialize = onInitialize)
else
list()
)
)
}
}
3 changes: 3 additions & 0 deletions R/shiny_data_filter_item.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ shiny_data_filter_item_ui <- function(inputId, verbose = FALSE) {
#' session
#' @param data a \code{reactive expression} returning a \code{data.frame} to use
#' as the input to the filter item module
#' @param column_name A column name to initialize the filter item with. If
#' unspecified or \code{NULL}, the filter item is initialized in its column
#' selection state.
#' @inheritParams columnSelectInput
#' @param verbose a \code{logical} value indicating whether or not to print log
#' statements out to the console
Expand Down
6 changes: 5 additions & 1 deletion R/shiny_vector_filter.R
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ shiny_vector_filter_ui.default <- function(data, inputId) {
#'
#' @param data the data object to be filtered
#' @param inputId The \code{input} slot that will be used to access the value.
#' @param global A \code{logical} value indicating whether the call is issued
#' through global methods search. Typically does not need to be specified
#' unless explicitly trying to avoid a global search for methods.
#'
#' @return a shiny server function as described in the details
#'
Expand Down Expand Up @@ -121,9 +124,10 @@ shiny_vector_filter.default <- function(data, inputId, ...) {
#' @return a pillar formatted class name
#'
#' @importFrom pillar type_sum
#' @importFrom utils methods
#'
get_dataFilter_class <- function(obj) {
vf_methods <- gsub(".*\\.", "", as.character(methods(shiny_vector_filter)))
vf_methods <- gsub(".*\\.", "", as.character(utils::methods(shiny_vector_filter)))

if ("numeric" %in% vf_methods)
vf_methods <- c(vf_methods, "real", "double", "integer")
Expand Down
4 changes: 4 additions & 0 deletions man/shiny_data_filter_item.Rd

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

4 changes: 4 additions & 0 deletions man/shiny_vector_filter.Rd

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

0 comments on commit 4e95eae

Please sign in to comment.