【问题标题】:change data for next input dynamically动态更改下一个输入的数据
【发布时间】:2015-03-14 03:44:31
【问题描述】:

我有两个选择输入 用户界面 图书馆(闪亮)

ContextElements = c("choice1", "choice2", "choice3")
shinyUI(pageWithSidebar(

headerPanel(""),

sidebarPanel(
  h4("test for selectize input"),

 selectizeInput(inputId = "firstAxe", label = h4("First Axe"),  
               choices=ContextElements, selected = NULL, multiple = FALSE,
               options = NULL),
 hr(),

 selectizeInput(inputId = "twoAxe", label = h4("Second Axe"),  
               choices=NULL, selected = NULL, multiple = FALSE,
               options = NULL)
),
mainPanel(
  )
))

我希望下一个 selectizeinput 选项(“twoAxe”)用第一个选项中剩余的选项动态填充,这意味着如果我选择了第一个选项,如果第一个选项,第二个选项将是选项 2 和选项 3

谢谢

【问题讨论】:

  • 如果没有完整的代码可以使用,我想您可以在 server.R 端执行此操作,并带有某种反应性,其中包括 ContextElements_new <- ContextElements[!(ContextElements %in% input$firstAxe)] 的效果但这只是一个猜测,需要一些修补。有人可能会提供更好的答案。或者,您可以包含 server.R 和 UI.r 的可重现代码,并且可能会出现更好/正确的解决方案。

标签: r shiny


【解决方案1】:

您可以在 server.r 中使用 updateSelectizeInput 执行此操作。让我们假设ContextElements 可用于服务器 - 在global.rserver.rui.r 中定义。那么这应该工作:

observe({

    input$firstAxe   # makes the second selectize change when the first one does

    updateSelectizeInput({session, inputId="twoAxe",
         choices=as.list( ContextElements[!ContextElements %in% input$firstAxe] )  })
})

当您更改firstAxe 中的选择时,您应该会看到twoAxe 中的选择响应。

【讨论】:

  • 应该是 updateSelectizeInput(..) 而不是 updateSelectizeInput({..})
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-02-22
  • 2017-02-03
  • 1970-01-01
  • 2021-12-27
  • 1970-01-01
相关资源
最近更新 更多