我正在尝试添加一个新选项来通过传单中的 easybutton 选择 selectizeInput。
我得到的是一个未定义的选项
这是一个例子:
library(shiny)
library(leaflet)
shinyApp(
ui <- fluidPage(
selectizeInput("countries", "Country :", choices = c("Worldwide") ),
leafletOutput("countryMap",height="500px")
),
server <- function(input, output, session){
output$countryMap <- renderLeaflet({
leaflet() %>%
addEasyButton(easyButton(icon = "fa-check", id = "doneMap", position = "topright", title = "Finish",
onClick = JS("function(btn, map){
var $select = $('#countries').selectize();
var selectize = $select[0].selectize;
selectize.addOption({ value: 'selectedRegion', text: 'Selected Region' });
selectize.addItem('selectedRegion');
}
"))) %>%
addProviderTiles(providers$Esri.WorldStreetMap)
})
})
唯一的问题ID是
data
中的addOption(data)
是需要value
和label
键的对象,而不是value
和text
:
...,
onClick = JS("function(btn, map){
var $select = $('#countries').selectize();
var selectize = $select[0].selectize;
selectize.addOption({value: 'selectedRegion', label: 'Selected Region'});
selectize.addItem('selectedRegion');
}")