I want to customize a selectizeInput
in shiny
, similar to this example from https://selectize.github.io/selectize.js/. The value and label should be different and it should be possible to select more than 1 entry and add new entries (using the create = TRUE
option). I have tried with selectizeInput
und pickerInput
from shinyWidgets
but cannot get it to work.
0
votes
2 Answers
2
votes
The option render
allows to set the items in HTML. Here is an example:
library(shiny)
itemValues <- c("foo", "bar")
itemNames <- sprintf("<span style='background-color:springgreen'>%s</span>",
itemValues)
items <- setNames(itemValues, itemNames)
shinyApp(
ui = fluidPage(
selectizeInput("id", "Label", choices = items,
options = list(render = I("
{
item: function(item, escape) { return '<div>' + item.label + '</div>'; },
option: function(item, escape) { return '<div>' + item.label + '</div>'; }
}")))
),
server = function(input, output) {}
)
1
votes
You can look here for some examples: shiny selectize examples
Most of the advanced options are set via the options. A minimal example without color is here:
ui <- fluidPage(
selectizeInput('myInput',
label='Select',
choices=c('first choice' = 'c1'),
multiple = TRUE,
options = list(create = TRUE))
)