【问题标题】:Clear selectizeInput dynamically动态清除 selectizeInput
【发布时间】: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 时,仍会选择所选择的元素。 ObserveEvent 或 observe 与 updateSelectizeInput 组合仅在呈现 ui 并且用于重置输入的 shinyjs 代码也不起作用时才有效。

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

谢谢你:-)

【问题讨论】:

    标签: r shiny selectize.js


    【解决方案1】:

    我使用了一种解决方法:

    我删除了条件:

       if(input$numbergroups > 4) {
        ...
    }
    

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

    【讨论】:

      猜你喜欢
      • 2018-12-22
      • 1970-01-01
      • 2019-03-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-28
      • 2022-01-18
      • 2012-04-21
      相关资源
      最近更新 更多