下面的代码工作正常,我想要的唯一附加组件是在选择所有内容后其余所有都按原样显示“ All”,也就是说,如果选择1选项,则显示1/11水果,依此类推。有人可以帮我吗?
ui <- fluidPage(
column(
width = 4,
pickerInput(
inputId = "id", label = "Choices :",
choices = c("Banana", "Blueberry", "Cherry", "Coconut", "Grapefruit",
"Kiwi", "Lemon", "Lime", "Mango", "Orange", "Papaya"),
options = list(`actions-box` = TRUE, `selected-text-format` = "count > 0",
`count-selected-text` = "{0}/{1} fruits"),
multiple = TRUE
)
)
)
server <- function(input, output) {
output$res <- renderPrint({
input$id
})
}
shinyApp(ui = ui, server = server)
答案 0 :(得分:0)
我不知道闪亮的小部件的全部功能,但是可以肯定的是,可以通过自定义消息将信息从服务器发送回UI来实现。这是我的操作方式,尽管它看起来确实有点黑。
ui <- fluidPage(
column(
width = 4,
pickerInput(
inputId = "id", label = "Choices :",
choices = c("Banana", "Blueberry", "Cherry", "Coconut", "Grapefruit",
"Kiwi", "Lemon", "Lime", "Mango", "Orange", "Papaya"),
options = list(`actions-box` = TRUE,
`selected-text-format` = "count > 0",
`count-selected-text` = "{0}/{1} fruits"
),
multiple = TRUE
)
),
singleton({
tags$head(tags$script(
"Shiny.addCustomMessageHandler(\"testmessage\",
function(message) {
var x = document.getElementsByClassName(\"filter-option pull-left\");
x[0].innerHTML = message;
}
);"
))
})
)
server <- function(input,output,session) {
output$res <- renderPrint({
input$id
})
numOptions = 11
observe({
if(length(input$id) == numOptions){
session$sendCustomMessage(type = 'testmessage',
message = list("All"))
}
})
}
shinyApp(ui = ui, server = server)
在这里,我检查是否在服务器功能的观察者中选择了所有元素。如果是这样,我会在用户界面上触发一个简单的javascript函数。