有没有一种方法可以将HTML标记(例如h6)用于updateSelectizeInput(适用于selectInput,请参见下面的代码)?使用下面的代码,只需在updateSelectizeInput [object Object]中使用h6(“ Label”)即可显示为输出。
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))
谢谢
如果标签将始终相同,则不要为label
on设置值updateSelectizeInput
。实际上,您只应设置要更改的参数。
举例来说,这仅更改所选的值:
updateSelectizeInput(session, 'DropDownSelectize', selected = "choice3")
如果label
需要更改值,但需要使用标签或样式(例如在这种情况下)h6
,则可以使用shinyjs
来仅更改标签的文本。为此,您需要id
在h6
标签中添加一个。请参见下面的示例,其中第一个观察者内部的标签使用的html
功能进行了更改shinyjs
。我还添加了两个按钮来手动更改标签的文本。
library(shiny)
library(shinyjs)
ui =fluidPage(
shinyjs::useShinyjs(), # to initialize shinyjs
selectizeInput('DropDownSelectize',choices=NULL,label=h6("", id = "labelText")),
selectInput('DropDownSelect',choices = c("choice1","choice2","choice3"),
label=h6("Label")),
actionButton("useLabel1", "Use Label 1"),
actionButton("useLabel2", "Use Label 2")
)
server = function(input, output, session) {
observe({
updateSelectizeInput(session,
'DropDownSelectize',
# label = h6("Label"), # no needed
choices = c("choice1","choice2","choice3"),
selected = "choice1",
server = TRUE)
shinyjs::html("labelText", "Label")
})
observeEvent(input$useLabel1, {
shinyjs::html("labelText", "Label 1")
})
observeEvent(input$useLabel2, {
shinyjs::html("labelText", "Label 2")
})
}
runApp(list(ui = ui, server = server))
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句