Learn R Programming

shinyfilters (version 0.3.0)

updateFilterInput: Update a shiny Input

Description

Updates a shiny input based the type of object x and other arguments.

Usage

updateFilterInput(x, ...)

Value

The result of the following shiny input updates is returned, based on the type of object passed to x, and other specified arguments.

ValuexArguments
shiny::updateDateInputDate, POSIXtdefault
shiny::updateDateRangeInputDate, POSIXtrange = TRUE
shiny::updateNumericInputnumericdefault
shiny::updateRadioButtonscharacter, factor, list, logicalradio = TRUE
shiny::updateSelectInputcharacter, factor, list, logicaldefault
shiny::updateSelectizeInputcharacter, factor, list, logicalselectize = TRUE
shiny::updateSliderInputnumericslider = TRUE
shiny::updateTextAreaInputcharactertextbox = TRUE, area = TRUE
shiny::updateTextInputcharactertextbox = TRUE

Arguments

x

The object used to create the input.

...

Arguments used for input selection or passed to the selected input update function. See details.

Details

The following arguments passed to ... are supported:

area

(character). Logical. Controls whether to use shiny::updateTextAreaInput (TRUE) or shiny::updateTextInput (FALSE, default). Only applies when textbox is TRUE.

radio

(character, factor, list, logical). Logical. Controls whether to use shiny::updateRadioButtons (TRUE) or a dropdown input update function (FALSE, default). For character vectors, radio only applies if textbox is FALSE, the default.

range

(Date, POSIXt). Logical. Controls whether to use shiny::updateDateRangeInput (TRUE) or shiny::updateDateInput (FALSE, default).

selectize

(character, factor, list, logical). Logical. Controls whether to use shiny::updateSelectizeInput (TRUE) or shiny::updateSelectInput (FALSE, default). For character vectors, selectize only applies if textbox is FALSE, the default.

slider

(numeric). Logical. Controls whether to use shiny::updateSliderInput (TRUE) or shiny::updateNumericInput (FALSE, default).

textbox

(character). Logical. Controls whether to update a text input (TRUE) or a dropdown input (FALSE, default).

Remaining arguments passed to ... are passed to args_update_filter_input() or the selected input update function.

Examples

Run this code
if (FALSE) { # interactive()
library(shiny)

fruits <- list(
	"a" = c("apples", "avocados"),
	"b" = c("bananas", "blueberries"),
	"c" = c("cherries", "cantaloupe")
)

ui <- fluidPage(
	sidebarLayout(
		sidebarPanel(
			filterInput(
				x = letters[1:3],
				inputId = "letter",
				label = "Pick a letter:",
       multiple = TRUE
			),
			filterInput(
				x = fruits,
				inputId = "fruits",
				label = "Pick a fruit:"
			)
		),
   mainPanel()
	)
)

server <- function(input, output, session) {
	shiny::observe({
		fruits_filtered <- fruits
		if (!is.null(input$letter) && length(input$letter) != 0L) {
			fruits_filtered <- fruits[input$letter]
		}
		# Call updateFilterInput() inside the shiny server:
		updateFilterInput(x = fruits_filtered, inputId = "fruits")
	})
}
shinyApp(ui, server)
}

Run the code above in your browser using DataLab