Skip to content

Commit

Permalink
remove unnecessary refresh in picker bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
pvictor committed Nov 11, 2019
1 parent 7139cf5 commit 6b0034c
Show file tree
Hide file tree
Showing 7 changed files with 331 additions and 279 deletions.
161 changes: 12 additions & 149 deletions R/input-selectpicker.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,168 +30,31 @@
#' shinyWidgetsGallery()
#'
#'
#' # Simple example
#' # Basic usage
#' library("shiny")
#' ui <- fluidPage(
#' pickerInput(inputId = "somevalue", label = "A label", choices = c("a", "b")),
#' verbatimTextOutput("value")
#' )
#' server <- function(input, output) {
#' output$value <- renderPrint({ input$somevalue })
#' }
#' shinyApp(ui, server)
#'
#'
#' ### Add actions box for selecting
#' # deselecting all options
#'
#' library("shiny")
#' library("shinyWidgets")
#'
#' ui <- fluidPage(
#' br(),
#' pickerInput(
#' inputId = "p1",
#' label = "Select all option",
#' choices = rownames(mtcars),
#' multiple = TRUE,
#' options = list(`actions-box` = TRUE)
#' ),
#' br(),
#' pickerInput(
#' inputId = "p2",
#' label = "Select all option / custom text",
#' choices = rownames(mtcars),
#' multiple = TRUE,
#' options = list(
#' `actions-box` = TRUE,
#' `deselect-all-text` = "None...",
#' `select-all-text` = "Yeah, all !",
#' `none-selected-text` = "zero"
#' )
#' )
#' )
#'
#' server <- function(input, output, session) {
#'
#' }
#'
#' shinyApp(ui = ui, server = server)
#'
#'
#'
#' ### Customize the values displayed in the box ----
#'
#' library("shiny")
#' library("shinyWidgets")
#' library(shinyWidgets)
#'
#' ui <- fluidPage(
#' br(),
#' pickerInput(
#' inputId = "p1",
#' label = "Default",
#' multiple = TRUE,
#' choices = rownames(mtcars),
#' selected = rownames(mtcars)[1:5]
#' inputId = "somevalue",
#' label = "A label",
#' choices = c("a", "b")
#' ),
#' br(),
#' pickerInput(
#' inputId = "p1b",
#' label = "Default with | separator",
#' multiple = TRUE,
#' choices = rownames(mtcars),
#' selected = rownames(mtcars)[1:5],
#' options = list(`multiple-separator` = " | ")
#' ),
#' br(),
#' pickerInput(
#' inputId = "p2",
#' label = "Static",
#' multiple = TRUE,
#' choices = rownames(mtcars),
#' selected = rownames(mtcars)[1:5],
#' options = list(`selected-text-format`= "static",
#' title = "Won't change")
#' ),
#' br(),
#' pickerInput(
#' inputId = "p3",
#' label = "Count",
#' multiple = TRUE,
#' choices = rownames(mtcars),
#' selected = rownames(mtcars)[1:5],
#' options = list(`selected-text-format`= "count")
#' ),
#' br(),
#' pickerInput(
#' inputId = "p3",
#' label = "Customize count",
#' multiple = TRUE,
#' choices = rownames(mtcars),
#' selected = rownames(mtcars)[1:5],
#' options = list(
#' `selected-text-format`= "count",
#' `count-selected-text` = "{0} models choosed (on a total of {1})"
#' )
#' )
#' verbatimTextOutput("value")
#' )
#'
#' server <- function(input, output, session) {
#'
#' }
#'
#' shinyApp(ui = ui, server = server)
#'
#'
#'
#' ### Limit the number of selections ----
#'
#' library(shiny)
#' library(shinyWidgets)
#' ui <- fluidPage(
#' pickerInput(
#' inputId = "groups",
#' label = "Select one from each group below:",
#' choices = list(
#' Group1 = c("1", "2", "3", "4"),
#' Group2 = c("A", "B", "C", "D")
#' ),
#' multiple = TRUE,
#' options = list("max-options-group" = 1)
#' ),
#' verbatimTextOutput(outputId = "res_grp"),
#' pickerInput(
#' inputId = "groups_2",
#' label = "Select two from each group below:",
#' choices = list(
#' Group1 = c("1", "2", "3", "4"),
#' Group2 = c("A", "B", "C", "D")
#' ),
#' multiple = TRUE,
#' options = list("max-options-group" = 2)
#' ),
#' verbatimTextOutput(outputId = "res_grp_2"),
#' pickerInput(
#' inputId = "classic",
#' label = "Select max two option below:",
#' choices = c("A", "B", "C", "D"),
#' multiple = TRUE,
#' options = list(
#' "max-options" = 2,
#' "max-options-text" = "No more!"
#' )
#' ),
#' verbatimTextOutput(outputId = "res_classic")
#' )
#' server <- function(input, output) {
#' output$res_grp <- renderPrint(input$groups)
#' output$res_grp_2 <- renderPrint(input$groups_2)
#' output$res_classic <- renderPrint(input$classic)
#' output$value <- renderPrint(input$somevalue)
#' }
#'
#' shinyApp(ui, server)
#'
#' }
#'
#' @example examples/picker-select-all.R
#' @example examples/picker-value-display.R
#' @example examples/picker-limits.R
#'
#' @importFrom shiny restoreInput
#' @importFrom htmltools tags htmlEscape validateCssUnit
#' tagAppendAttributes tagAppendChildren tag
Expand Down
54 changes: 54 additions & 0 deletions examples/picker-limits.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
### Limit the number of selections ----

if (interactive()) {

library(shiny)
library(shinyWidgets)

ui <- fluidPage(
pickerInput(
inputId = "groups",
label = "Select one from each group below:",
choices = list(
Group1 = c("1", "2", "3", "4"),
Group2 = c("A", "B", "C", "D")
),
multiple = TRUE,
options = list("max-options-group" = 1)
),
verbatimTextOutput(outputId = "res_grp"),
pickerInput(
inputId = "groups_2",
label = "Select two from each group below:",
choices = list(
Group1 = c("1", "2", "3", "4"),
Group2 = c("A", "B", "C", "D")
),
multiple = TRUE,
options = list("max-options-group" = 2)
),
verbatimTextOutput(outputId = "res_grp_2"),
pickerInput(
inputId = "classic",
label = "Select max two option below:",
choices = c("A", "B", "C", "D"),
multiple = TRUE,
options = list(
"max-options" = 2,
"max-options-text" = "No more!"
)
),
verbatimTextOutput(outputId = "res_classic")
)

server <- function(input, output) {

output$res_grp <- renderPrint(input$groups)
output$res_grp_2 <- renderPrint(input$groups_2)
output$res_classic <- renderPrint(input$classic)

}

shinyApp(ui, server)

}
45 changes: 45 additions & 0 deletions examples/picker-select-all.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
### Add actions box for selecting ----
### deselecting all options

if (interactive()) {

library(shiny)
library(shinyWidgets)

ui <- fluidPage(
tags$h2("Select / Deselect all"),
pickerInput(
inputId = "p1",
label = "Select all option",
choices = rownames(mtcars),
multiple = TRUE,
options = list(`actions-box` = TRUE)
),
verbatimTextOutput("r1"),
br(),
pickerInput(
inputId = "p2",
label = "Select all option / custom text",
choices = rownames(mtcars),
multiple = TRUE,
options = list(
`actions-box` = TRUE,
`deselect-all-text` = "None...",
`select-all-text` = "Yeah, all !",
`none-selected-text` = "zero"
)
),
verbatimTextOutput("r2")
)

server <- function(input, output, session) {

output$r1 <- renderPrint(input$p1)
output$r2 <- renderPrint(input$p2)

}

shinyApp(ui = ui, server = server)

}

66 changes: 66 additions & 0 deletions examples/picker-value-display.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
### Customize the values displayed in the box ----

if (interactive()) {

library(shiny)
library(shinyWidgets)

ui <- fluidPage(
br(),
pickerInput(
inputId = "p1",
label = "Default",
multiple = TRUE,
choices = rownames(mtcars),
selected = rownames(mtcars)[1:5]
),
br(),
pickerInput(
inputId = "p1b",
label = "Default with | separator",
multiple = TRUE,
choices = rownames(mtcars),
selected = rownames(mtcars)[1:5],
options = list(`multiple-separator` = " | ")
),
br(),
pickerInput(
inputId = "p2",
label = "Static",
multiple = TRUE,
choices = rownames(mtcars),
selected = rownames(mtcars)[1:5],
options = list(`selected-text-format`= "static",
title = "Won't change")
),
br(),
pickerInput(
inputId = "p3",
label = "Count",
multiple = TRUE,
choices = rownames(mtcars),
selected = rownames(mtcars)[1:5],
options = list(`selected-text-format`= "count")
),
br(),
pickerInput(
inputId = "p3",
label = "Customize count",
multiple = TRUE,
choices = rownames(mtcars),
selected = rownames(mtcars)[1:5],
options = list(
`selected-text-format`= "count",
`count-selected-text` = "{0} models choosed (on a total of {1})"
)
)
)

server <- function(input, output, session) {

}

shinyApp(ui = ui, server = server)

}

2 changes: 1 addition & 1 deletion inst/assets/selectPicker/picker-bindings.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ var pickerInputBinding = new Shiny.InputBinding();
},
subscribe: function subscribe(el, callback) {
$(el).on('changed.bs.select', function (event) {
$(el).selectpicker('refresh');
//$(el).selectpicker('refresh');
callback();
});
},
Expand Down
2 changes: 1 addition & 1 deletion inst/assets/shinyWidgets-bindings.min.js

Large diffs are not rendered by default.

Loading

0 comments on commit 6b0034c

Please sign in to comment.