动态清除 selectizeInput

Posted

技术标签:

【中文标题】动态清除 selectizeInput【英文标题】:Clear selectizeInput dynamically 【发布时间】:2019-01-03 02:04:26 【问题描述】:

我使用多个由“renderUI”创建的 selectizeInput 字段。

    output$groupe <- renderUI (
    if(input$numbergroups > 4) 
    KG = c("control group", "")
    TV = c("1 x 1st position in ad break", "1 x PreSplit before ad break", "1 x TV spot within ad break", "2 x TV spot within ad break", "TV spot within ad break & PreSplit before ad break", "1st position in ad break & PreSplit before ad break", "")
    YT = c("1 x YouTube Trueview Desktop", "2 x YouTube Trueview Desktop", "1 x YouTube PreRoll Desktop", "2 x YouTube PreRoll Desktop", "1 x YouTube TrueView Mobile", "2 x YouTube TrueView Mobile",
           "1 x YouTube Bumper Mobile", "2 x YouTube Bumper Mobile", "YouTube Trueview Desktop & YouTube TrueView Mobile", "YouTube Trueview Desktop & YouTube Bumper Mobile",
           "YouTube PreRoll Desktop & YouTube Bumper Mobile", "YouTube TrueView Mobile & YouTube Bumper Mobile", "")
    FB = c("1 x Facebook Post Video", "2 x Facebook Post Video", "")
    TVYTFB = c("TV spot within ad break & YouTube Trueview Desktop", "TV spot within ad break & YouTube PreRoll Desktop", "TV spot within ad break & YouTube TrueView Mobile", "TV spot within ad break & YouTube Bumper Mobile", "TV spot within ad break & Facebook Post Video", "")
    YTFB = c("YouTube Trueview Desktop & Facebook Post Video", "YouTube PreRoll Desktop & Facebook Post Video", "YouTube TrueView Mobile & Facebook Post Video", "YouTube Bumper Mobile & Facebook Post Video", "")

    TV <- TV[!TV %in% input$groupa & !TV %in% input$groupb & !TV %in% input$groupc & !TV %in% input$groupd & !TV %in% input$groupf]
    YT <- YT[!YT %in% input$groupa & !YT %in% input$groupb & !YT %in% input$groupc & !YT %in% input$groupd & !YT %in% input$groupf]
    FB <- FB[!FB %in% input$groupa & !FB %in% input$groupb & !FB %in% input$groupc & !FB %in% input$groupd & !FB %in% input$groupf]
    TVYTFB <- TVYTFB[!TVYTFB %in% input$groupa & !TVYTFB %in% input$groupb & !TVYTFB %in% input$groupc & !FB %in% input$groupd & !FB %in% input$groupf]
    KG <- KG[!KG %in% input$groupa & !KG %in% input$groupb & !KG %in% input$groupc & !KG %in% input$groupd & !KG %in% input$groupf]
    YTFB <- YTFB[!YTFB %in% input$groupa & !YTFB %in% input$groupb & !YTFB %in% input$groupc & !YTFB %in% input$groupd & !YTFB %in% input$groupf]

    selected <- input$groupe
    selectizeInput("groupe", "Experimental group E", list(
        "control group" = KG,
        "TV" = TV,
        "YouTube" = YT,
        "Facebook" = FB,
        "TV & (YouTube | Facebook)" = TVYTFB,
        "YouTube & Facebook" = YTFB
    ), multiple = TRUE, selected = selected, options = list(placeholder = "Please choose at least one channel", plugins = list('remove_button')))
 else 
    shinyjs::reset(input$groupe)
    shinyjs::hide(input$groupe)

)

这是仅创建其中一个元素的代码。当input$numbergroups 为 4 或更少时,将不会呈现此输入。但是,当用户选择一个或多个元素并将 input$numbersgroups 更改为 3 时,当我再次将 input$numbergroups 更改为 5 时,仍会选择所选择的元素。 ObserveEventobserveupdateSelectizeInput 组合仅在呈现 ui 并且用于重置输入的 shinyjs 代码也不起作用时才有效。

有没有办法在每次不渲染时动态重置输入字段?

谢谢你:-)

【问题讨论】:

【参考方案1】:

我使用了一种解决方法:

我删除了条件:

   if(input$numbergroups > 4) 
    ...

之后,我读出了input$numbergroups 的值并使用计划javascript 动态显示和隐藏它们:-)

【讨论】:

以上是关于动态清除 selectizeInput的主要内容,如果未能解决你的问题,请参考以下文章

如何动态清除用户控件中的所有控件?

如何在AQADMIN中动态清除表

如何清除 Hackerrank 动态数组运行时错误?

nginx_cache_purge模块如何动态清除缓存,加分?

jqgrid 表格中筛选条件的多选下拉,树形下拉 ;文本框清除插件;高级查询多条件动态筛选插件

Oracle监听日志清除