-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #145 from Appsilon/dev-copy
Update dropdown and uibutton
- Loading branch information
Showing
31 changed files
with
506 additions
and
155 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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
Package: shiny.semantic | ||
Type: Package | ||
Title: Semantic UI Support for Shiny | ||
Version: 0.2.4.9001 | ||
Version: 0.2.4.9002 | ||
Authors@R: c(person("Filip", "Stachura", email = "[email protected]", | ||
role = "aut"), | ||
person("Dominik", "Krzeminski", email = "[email protected]", | ||
|
@@ -30,4 +30,4 @@ Suggests: | |
testthat, | ||
lintr, | ||
covr | ||
RoxygenNote: 6.1.1 | ||
RoxygenNote: 7.0.0 |
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,15 @@ | ||
#' Create Semantic UI Button | ||
#' | ||
#' @param name The \code{input} slot that will be used to access the value. | ||
#' @param label The contents of the button or link | ||
#' @param icon An optional \code{\link{uiicon}()} to appear on the button. | ||
#' @param type An optional attribute to be added to the button's class. | ||
#' @param ... Named attributes to be applied to the button | ||
#' | ||
#' @examples | ||
#' uibutton("simple_button", "Press Me!") | ||
#' | ||
#' @export | ||
uibutton <- function(name, label, icon = NULL, type = NULL, ...) { | ||
tags$button(id = name, class = paste("ui", type, "button"), label, icon, ...) | ||
} |
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,98 @@ | ||
#' Create dropdown Semantic UI component | ||
#' | ||
#' This creates a default dropdown using Semantic UI styles with Shiny input. | ||
#' Dropdown is already initialized and available under input[[name]]. | ||
#' | ||
#' @param name Input name. Reactive value is available under input[[name]]. | ||
#' @param choices All available options one can select from. | ||
#' @param choices_value What reactive value should be used for corresponding | ||
#' choice. | ||
#' @param default_text Text to be visible on dropdown when nothing is selected. | ||
#' @param value Pass value if you want to initialize selection for dropdown. | ||
#' @param type Change depending what type of dropdown is wanted. | ||
#' | ||
#' @examples | ||
#' ## Only run examples in interactive R sessions | ||
#' if (interactive()) { | ||
#' | ||
#' library(shiny) | ||
#' library(shiny.semantic) | ||
#' ui <- function() { | ||
#' shinyUI( | ||
#' semanticPage( | ||
#' title = "Dropdown example", | ||
#' suppressDependencies("bootstrap"), | ||
#' uiOutput("dropdown"), | ||
#' p("Selected letter:"), | ||
#' textOutput("selected_letter") | ||
#' ) | ||
#' ) | ||
#' } | ||
#' server <- shinyServer(function(input, output) { | ||
#' output$dropdown <- renderUI({ | ||
#' dropdown("simple_dropdown", LETTERS, value = "A") | ||
#' }) | ||
#' output$selected_letter <- renderText(input[["simple_dropdown"]]) | ||
#' }) | ||
#' | ||
#' shinyApp(ui = ui(), server = server) | ||
#' } | ||
#' | ||
#' @export | ||
dropdown <- function(name, choices, choices_value = choices, | ||
default_text = "Select", value = NULL, type = "selection fluid") { | ||
shiny::div( | ||
id = name, class = paste("ui", type, "dropdown semantic-select-input"), | ||
tags$input(type = "hidden", name = name, value = value), | ||
uiicon("dropdown"), | ||
shiny::div(class = "default text", default_text), | ||
uimenu( | ||
purrr::when( | ||
choices, | ||
is.null(names(.)) ~ | ||
purrr::map2( | ||
choices, choices_value, | ||
~ shiny::div(class = paste0(if (.y %in% value) "active ", "item"), `data-value` = .y, .x) | ||
), | ||
!is.null(names(.)) ~ | ||
purrr::map( | ||
seq_len(length(choices)), ~ { | ||
shiny::tagList( | ||
menu_header(names(choices)[.x], is_item = FALSE), | ||
menu_divider(), | ||
purrr::map2( | ||
choices[[.x]], choices_value[[.x]], | ||
~ shiny::div(class = paste0(if (.y %in% value) "active ", "item"), `data-value` = .y, .x) | ||
) | ||
) | ||
} | ||
) | ||
) | ||
) | ||
) | ||
} | ||
|
||
#' Update dropdown Semantic UI component | ||
#' | ||
#' Change the value of a \code{\link{dropdown}} input on the client. | ||
#' | ||
#' @param session The \code{session} object passed to function given to \code{shinyServer}. | ||
#' @param name The id of the input object | ||
#' @param choices All available options one can select from. If no need to update then leave as \code{NULL} | ||
#' @param choices_value What reactive value should be used for corresponding choice. | ||
#' @param value The initially selected value. | ||
#' | ||
#' @export | ||
update_dropdown <- function(session, name, choices = NULL, choices_value = choices, value = NULL) { | ||
if (!is.null(value)) value <- paste(as.character(value), collapse = ",") else value <- NULL | ||
if (!is.null(choices)) { | ||
options <- jsonlite::toJSON(data.frame(name = choices, text = choices, value = choices_value)) | ||
} else { | ||
options <- NULL | ||
} | ||
|
||
message <- list(label = label, choices = options, value = value) | ||
message <- message[!vapply(message, is.null, FUN.VALUE = logical(1))] | ||
|
||
session$sendInputMessage(name, message) | ||
} |
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
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
Oops, something went wrong.