为了将selectizeInput 的选项视为HTML,render 选项是要走的路。以下代码将呈现普通输出:
library(shiny)
shinyApp(
ui = fluidPage(
br(),
selectizeInput(
"slctz", "Select something:",
choices = list("option1" = "value1", "option2" = "value2"),
options = list(
render = I("{
item: function(item, escape) {
return '<span>' + item.label + '</span>';
},
option: function(item, escape) {
return '<span>' + item.label + '</span>';
}
}")
)
)
),
server = function(input, output) {}
)
option 字段用于选项列表,而item 字段用于选定选项。
因此,如果您想要设置选项和选定选项的样式,您可以通过将class 属性添加到span 元素并在UI 中定义您的CSS 类来简洁地做到这一点:
ui = fluidPage(
tags$head(
tags$style(
HTML(
"
.myoption {......}
.myitem {......}
"
)
)
),
br(),
selectizeInput(
"slctz", "Select something:",
choices = list("option1" = "value1", "option2" = "value2"),
options = list(
render = I("{
item: function(item, escape) {
return '<span class=\"myitem\">' + item.label + '</span>';
},
option: function(item, escape) {
return '<span class=\"myoption\">' + item.label + '</span>';
}
}")
)
)
)