在带有R的selectizeInput中使用html
我想在select(ize)输入的选项中使用一些html。有谁知道一个简单的解决方案,如何告诉shiny将选项作为HTML处理在带有R的selectizeInput中使用html,r,shiny,selectinput,R,Shiny,Selectinput,我想在select(ize)输入的选项中使用一些html。有谁知道一个简单的解决方案,如何告诉shiny将选项作为HTML处理 library(shiny) ui <- fluidPage( selectInput("test html use", label = "option", choices = c("<div title = 'This is option A'>opt A</div>",
library(shiny)
ui <- fluidPage(
selectInput("test html use", label = "option", choices = c("<div title = 'This is option A'>opt A</div>", "opt B"))
)
server <- function(input, output) {
}
shinyApp(ui = ui, server = server)
库(闪亮)
ui为了将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) {}
)
谢谢Stéphane,工作起来很有魅力!
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>';
}
}")
)
)
)