mirror of
https://github.com/agdamsbo/FreesearchR.git
synced 2026-06-19 12:37:30 +02:00
new vectorSelectInput to select vector with names displayed
This commit is contained in:
parent
469c7b01ad
commit
12db7a6025
6 changed files with 255 additions and 9 deletions
|
|
@ -10,7 +10,7 @@
|
|||
#### Current file: R//app_version.R
|
||||
########
|
||||
|
||||
app_version <- function()'250306_0759'
|
||||
app_version <- function()'250307_1438'
|
||||
|
||||
|
||||
########
|
||||
|
|
@ -64,7 +64,7 @@ baseline_table <- function(data, fun.args = NULL, fun = gtsummary::tbl_summary,
|
|||
#' @return a \code{\link[shiny]{selectizeInput}} dropdown element
|
||||
#'
|
||||
#' @importFrom shiny selectizeInput
|
||||
#' @keywords internal
|
||||
#' @export
|
||||
#'
|
||||
columnSelectInput <- function(inputId, label, data, selected = "", ...,
|
||||
col_subset = NULL, placeholder = "", onInitialize, none_label="No variable selected") {
|
||||
|
|
@ -2828,11 +2828,11 @@ m_redcap_readServer <- function(id) {
|
|||
})
|
||||
|
||||
output$arms <- shiny::renderUI({
|
||||
shiny::selectizeInput(
|
||||
vectorSelectInput(
|
||||
inputId = ns("arms"),
|
||||
selected = NULL,
|
||||
label = "Filter by events/arms",
|
||||
choices = arms()[[3]],
|
||||
data = stats::setNames(arms()[[3]],arms()[[1]]),
|
||||
multiple = TRUE
|
||||
)
|
||||
})
|
||||
|
|
@ -5207,6 +5207,108 @@ clean_date <- function(data){
|
|||
}
|
||||
|
||||
|
||||
########
|
||||
#### Current file: R//vectorSelectInput.R
|
||||
########
|
||||
|
||||
library(shiny)
|
||||
|
||||
#' A selectizeInput customized for named vectors
|
||||
#'
|
||||
#' @param inputId passed to \code{\link[shiny]{selectizeInput}}
|
||||
#' @param label passed to \code{\link[shiny]{selectizeInput}}
|
||||
#' @param data A named \code{vector} object from which fields should be populated
|
||||
#' @param selected default selection
|
||||
#' @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
|
||||
#'
|
||||
#' @returns a \code{\link[shiny]{selectizeInput}} dropdown element
|
||||
#' @export
|
||||
#'
|
||||
#' @examples
|
||||
#' if (shiny::interactive()) {
|
||||
#' shinyApp(
|
||||
#' ui = fluidPage(
|
||||
#' shiny::uiOutput("select"),
|
||||
#' tableOutput("data")
|
||||
#' ),
|
||||
#' server = function(input, output) {
|
||||
#' output$select <- shiny::renderUI({
|
||||
#' vectorSelectInput(
|
||||
#' inputId = "variable", label = "Variable:",
|
||||
#' data = c(
|
||||
#' "Cylinders" = "cyl",
|
||||
#' "Transmission" = "am",
|
||||
#' "Gears" = "gear"
|
||||
#' )
|
||||
#' )
|
||||
#' })
|
||||
#'
|
||||
#' output$data <- renderTable(
|
||||
#' {
|
||||
#' mtcars[, c("mpg", input$variable), drop = FALSE]
|
||||
#' },
|
||||
#' rownames = TRUE
|
||||
#' )
|
||||
#' }
|
||||
#' )
|
||||
#' }
|
||||
vectorSelectInput <- function(inputId,
|
||||
label,
|
||||
data,
|
||||
selected = "",
|
||||
...,
|
||||
placeholder = "",
|
||||
onInitialize) {
|
||||
datar <- if (shiny::is.reactive(data)) data else shiny::reactive(data)
|
||||
|
||||
labels <- sprintf(
|
||||
IDEAFilter:::strip_leading_ws('
|
||||
{
|
||||
"name": "%s",
|
||||
"label": "%s"
|
||||
}'),
|
||||
datar(),
|
||||
names(datar()) %||% ""
|
||||
)
|
||||
|
||||
choices <- stats::setNames(datar(), labels)
|
||||
|
||||
shiny::selectizeInput(
|
||||
inputId = inputId,
|
||||
label = label,
|
||||
choices = choices,
|
||||
selected = selected,
|
||||
...,
|
||||
options = c(
|
||||
list(render = I("{
|
||||
// format the way that options are rendered
|
||||
option: function(item, escape) {
|
||||
item.data = JSON.parse(item.label);
|
||||
return '<div style=\"padding: 3px 12px\">' +
|
||||
'<div><strong>' +
|
||||
escape(item.data.name) + ' ' +
|
||||
'</strong></div>' +
|
||||
(item.data.label != '' ? '<div style=\"line-height: 1em;\"><small>' + escape(item.data.label) + '</small></div>' : '') +
|
||||
'</div>';
|
||||
},
|
||||
|
||||
// avoid data vomit splashing on screen when an option is selected
|
||||
item: function(item, escape) {
|
||||
item.data = JSON.parse(item.label);
|
||||
return '<div>' +
|
||||
escape(item.data.name) +
|
||||
'</div>';
|
||||
}
|
||||
}"))
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
########
|
||||
#### Current file: /Users/au301842/freesearcheR/inst/apps/freesearcheR/ui.R
|
||||
########
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue