简体   繁体   English

条件输入列表闪亮r

[英]conditional input list shiny r

Imagine I've the following example, where I select one of three numbers, and than I have a selectlist with the number I choose plus 1, 2 and 3 if it is 1, or I have the number plus 10, 11 or 12, otherwise. 想象一下,我有一个下面的例子,我从三个数字中选择一个,然后有一个选择列表,我选择的数字加上1、2和3(如果是1),或者我的数字加上10、11或12。除此以外。

I'm having troubles when I try to use the input.sel as a variable, can someone explain why it is ok in the condition but it is not ok to use it as a variable? 我在尝试将input.sel用作变量时遇到麻烦,有人可以解释为什么在这种情况下还可以,但不能将其用作变量吗?

conditionalPanel("input.sidebarmenu === 'dashboard8'",
                        selectInput("sel", "Select:", c(1,2,3), selected = "1"),

    conditionalPanel(
         condition = "input.sel == '1'",
         selectInput("Role1", "Role:", c(input.sel+10,input.sel+11,input.sel+12 ), selected = "All")),
    conditionalPanel(
         condition = "input.sel != '1'",
         selectInput("Role2", "Role:", c(input.sel+1,input.sel+2,input.sel+3) , selected = "All")                            
),

You can use something like : 您可以使用类似:

In UI 在UI中

selectInput("Role1", "Role:", "", selected = ""))

and in Server 和在服务器中

observe({
updateSelectInput(session,"Role1",choices=input$sel+10:12,selected= input$sel+10:12))
})

or better observeEvent(input$sel,...) to change input only when sel changed 或更好的observeEvent(input$sel,...)仅在sel更改时更改输入

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM