Laksanakan fungsi pilih-semua PickerInput dan paparkan semua pilihan apabila "semua" diklik
P粉665679053
P粉665679053 2023-09-09 14:36:29
0
1
590

Dalamshiny应用程序中,当所有pickerInput()的选项都被选择时,我希望在pickerInput()内部显示单词"all"作为选项,当您点击它时,将显示所有三个选项。如果我们可以用selectInput()implementasi di bawah, maka tiada masalah, tetapi output yang dicetak tidak boleh terjejas. Apa patut saya buat?

library(shiny) library(shinyWidgets) ui <- fluidPage( uiOutput("pick"), verbatimTextOutput("PR") ) server <- function(input, output, session) { output$pick<-renderUI({ pickerInput( inputId = "p9", label = "健康保险", choices = unique(as.character(iris$Species)), width = "150px", selected = unique(as.character(iris$Species)), multiple = TRUE, options = list( `actions-box` = TRUE, `deselect-all-text` = "无", `select-all-text` = "全部", `none-selected-text` = "零" ) ) }) output$PR<-renderPrint({ input$p9 }) } shinyApp(ui, server)

P粉665679053
P粉665679053

membalas semua (1)
P粉739942405

Berikut ialah contoh berdasarkaninijawapan yang sangat bagus. Kami menggunakanclickHandler,它根据容器All的点击情况,改变dropdown-item的样式,使其在display: blockdisplay: none之间切换。请注意,在应用程序初始化时,如果所有选择都被选中,项目只会隐藏在Alldi sini.

library(shiny) library(shinyWidgets) js <- HTML( " $(function() { let observer = new MutationObserver(callback); function clickHandler(evt) { if ($('.dropdown-item').css('display') == 'block') { $('.dropdown-item').on('click', clickHandler).css('display', 'none'); } else { $('.dropdown-item').on('click', clickHandler).css('display', 'block'); } } function callback(mutations) { for (let mutation of mutations) { if (mutation.type === 'childList') { $('.dropdown-header').on('click', clickHandler).css('cursor', 'pointer'); if ($('#p9 option').length == $('#p9 :selected').length) { $('.dropdown-item').on('click', clickHandler).css('display', 'none'); } } } } let options = { childList: true, }; observer.observe($('.inner')[0], options); }) " ) choices <- list("All" = unique(as.character(iris$Species))) ui <- fluidPage( tags$head(tags$script(js)), pickerInput( inputId = "p9", label = "Health Insurance", choices = choices, width = "150px", selected = unlist(unname(choices)), multiple = TRUE, options = list( `actions-box` = TRUE, `deselect-all-text` = "None", `select-all-text` = "All", `none-selected-text` = "zero" ) ), verbatimTextOutput("PR") ) server <- function(input, output, session) { output$PR <- renderPrint({ input$p9 }) } shinyApp(ui, server)
    Muat turun terkini
    Lagi>
    kesan web
    Kod sumber laman web
    Bahan laman web
    Templat hujung hadapan
    Tentang kita Penafian Sitemap
    Laman web PHP Cina:Latihan PHP dalam talian kebajikan awam,Bantu pelajar PHP berkembang dengan cepat!