Shiny R Shining updateSelectizeInput标签的自定义HTML标记
有没有一种方法可以将HTML标记(例如h6)用于updateSelectizeInput(它适用于selectInput,请参见下面的代码)?下面的代码只需在updateSelectizeInput[object object]中使用h6(“标签”)即可显示为输出Shiny R Shining updateSelectizeInput标签的自定义HTML标记,shiny,selectize.js,Shiny,Selectize.js,有没有一种方法可以将HTML标记(例如h6)用于updateSelectizeInput(它适用于selectInput,请参见下面的代码)?下面的代码只需在updateSelectizeInput[object object]中使用h6(“标签”)即可显示为输出 rm(list = ls()) library(shiny) ui =fluidPage( selectizeInput('DropDownSelectize',choices=NULL,label=""), selec
rm(list = ls())
library(shiny)
ui =fluidPage(
selectizeInput('DropDownSelectize',choices=NULL,label=""),
selectInput('DropDownSelect',choices = c("choice1","choice2","choice3"),
label=h6("Label"))
)
server = function(input, output, session) {
observe({
updateSelectizeInput(session,
'DropDownSelectize',
label = h6("Label"),
choices = c("choice1","choice2","choice3"),
selected = "choice1",
server = TRUE)
})
}
runApp(list(ui = ui, server = server))
谢谢如果标签总是一样的,只需在
updateSelectizeInput
上不要为label
设置值即可。实际上,您应该只设置要更改的参数
根据实例,这只是更改选定的值:
updateSelectizeInput(会话“DropDownSelectize”,selected=“choice3”)
如果需要更改标签的值,但需要使用标签或样式,如本例中的h6
,则可以使用shinyjs
仅更改标签的文本。为此,您需要在h6
标记中添加id
。请参见下面的示例,在第一个观察者内部,使用shinyjs
的html
功能更改标签。我还添加了两个按钮来手动更改标签的文本
库(闪亮)
图书馆(shinyjs)
ui=fluidPage(
shinyjs::使用shinyjs(),#初始化shinyjs
selectizeInput('DropDownSelectize',choices=NULL,label=h6(“,id=“labelText”),
selectInput('DropDownSelect',choices=c(“choice1”、“choice2”、“choice3”),
标签=h6(“标签”),
操作按钮(“使用标签1”、“使用标签1”),
操作按钮(“使用标签2”,“使用标签2”)
)
服务器=功能(输入、输出、会话){
观察({
updateSelectizeInput(会话,
“减少选举人数”,
#标签=h6(“标签”),#无需
选项=c(“选项1”、“选项2”、“选项3”),
selected=“choice1”,
服务器=真)
shinyjs::html(“labelText”、“Label”)
})
observeEvent(输入$useLabel1{
shinyjs::html(“标签文本”、“标签1”)
})
observeEvent(输入$useLabel2{
shinyjs::html(“标签文本”、“标签2”)
})
}
runApp(列表(ui=ui,server=server))
这显然是一个bug。如果将更新中的h6
包装为.character,则会得到h6
标签。我将在github上提交错误报告