本文介绍了闪亮:多重选择输入,一个选择向量,离散选择?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

闪亮的新手.希望有人可以帮助我.

new to shiny. Hoping someone can help me out.

我从同一个向量中有几个 selectizeInput 的绘图选项.我的目标是让值在被选择后不显示在其他输入中.IE.如果在输入 2 中选择了值 1,则它不应在输入 1、3 或 4 中可用.

I have several selectizeInput's drawing choices from the same vector. My goal is to have values NOT show up in other Inputs after they have been chosen. ie. If value 1 has been chosen in Input 2, it should not be available in Input 1, 3 or 4.

ui<- shinyUI(fluidPage(

titlePanel("Selectize Test"),

sidebarPanel(
selectizeInput(
  "groupoptions1", "Group 1", choices = NULL, multiple = TRUE
),
selectizeInput(
  "groupoptions2", "Group 2", choices = NULL, multiple = TRUE
),
selectizeInput(
  "groupoptions3", "Group 3", choices = NULL, multiple = TRUE
),
selectizeInput(
  "groupoptions4", "Group 4", choices = NULL, multiple = TRUE
)

),

mainPanel(
  htmlOutput("grouplist")
)
))

server<- shinyServer(function(input, output, session) {

groupdata <- reactive({

  as.vector(1:30)

})

observe({
updateSelectizeInput(session, "groupoptions1", choices = groupdata())

updateSelectizeInput(session, "groupoptions2", choices = groupdata())

updateSelectizeInput(session, "groupoptions3", choices = groupdata())

updateSelectizeInput(session, "groupoptions4", choices = groupdata())
})


output$grouplist <- renderPrint({

  list(
    match(input$groupoptions1, groupdata()),
    match(input$groupoptions2, groupdata()),
    match(input$groupoptions3, groupdata()),
    match(input$groupoptions4, groupdata())
  )
})

})

我尝试为每个 selectizeInput 使用单独的选择向量,以减去另一个选择,但是每次该向量更新时,所有现有选择都会被擦除.

I've tried having separate choice vectors for each selectizeInput that subtracts the other's selection, but then each time that vector updates all existing choices get wiped.

非常感谢任何帮助!

推荐答案

当您使用所选参数更新选项输入的输入时,您可以并且需要设置这些值:

You can and need to set the values when you update the input for the options inputs using the parameter selected:

 updateSelectizeInput(session, "groupoptions1", choices = groupdata1(),
                      selected=c(2,3))

您需要根据需要调整该值.我将您的示例减少到两个列表并将所有相关部分移到观察

You need to adapt the value according to your needs.I reduced your example to two list and moved all the relevant parts to observe

  observe({
    vals1<-input$groupoptions1
    vals2<-input$groupoptions2

    cat("updata input ")
    cat(isolate(vals1))
    cat(" | ")
    cat(isolate(groupdata2()))
    cat("\n")
    updateSelectizeInput(session, "groupoptions1",
                         choices =  as.vector(1:10)[! 1:10 %in% vals2],
                         selected=vals1)
    updateSelectizeInput(session, "groupoptions2",
                         choices =as.vector(1:10)[! 1:10 %in% vals1],
                         selected=vals2)


  })

这篇关于闪亮:多重选择输入,一个选择向量,离散选择?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-28 08:17
查看更多