R Shiny selectInput依赖于另一个selectInput

时间:2016-01-21 16:32:37

标签: r shiny shinydashboard

我在下面有一些数据,我用它来创建R闪亮的圆环图,其中FacebookSdk.sdkInitialize(getApplicationContext()); if(AccessToken.getCurrentAccessToken() != null) { LoginManager.getInstance().logOut(); } 是一个角色。我希望能够选择我想要查看其分数的电子邮件,但是在第二个下拉列表中只会看到该电子邮件的活动日期。

例如,如果我在第一个下拉列表中选择了email = xxxx,我只希望看到“没有活动”#39;在日期选择字段中。而对于email = yyyy,我希望只看到6/17/14,6/18 / 14,16 / 19/14作为选择。

我在ui中试过了一种嵌套的子集。例如:

date

但是这仍然显示所有可能的日期选择

数据

> ui <- shinyUI(fluidPage(
+   sidebarLayout(
+     sidebarPanel(
+       selectInput('Select', 'Customer:', choices = unique(as.character(dat5$email))),
+       selectInput("User", "Date:", choices = dat5[dat5$email==input$Select,date])
+     ),
+     mainPanel(plotOutput("distPlot"))
+   )
+ ))

到目前为止我的代码:

app.R

email   date        variable    value   ymin    ymax
xxxx    no activity e_score         0   0       0
xxxx    no activity diff            1   0       1
yyyy    6/17/14     e_score    0.7472   0       0.7472
yyyy    6/17/14     diff       0.2528   0.7472  1
yyyy    6/18/14     e_score    0.373    0       0.373
yyyy    6/18/14     diff       0.627    0.373   1
yyyy    6/19/14     e_score    0.533    0       0.533
yyyy    6/19/14     diff       0.467    0.533   1

2 个答案:

答案 0 :(得分:23)

您无法访问应用的ui.R部分中的输入,因此您需要使用renderUi / uiOutput动态生成您的selectInput。

ui.R中,您可以添加:

uiOutput("secondSelection")

和您的server.R

 output$secondSelection <- renderUI({
                selectInput("User", "Date:", choices = as.character(dat5[dat5$email==input$Select,"date"]))
        })

答案 1 :(得分:2)

您也可以执行更改CartExtension的操作。至少该解决方案在我做过的App中有效。将其添加到ui.R应该具有相同的效果。

server.R

尽管它也是有用且强大的,但我发现它在没有observe({ updateSelectInput(session, "User", choices = as.character(dat5[dat5$email==input$Select, date])) }) 的情况下变得“干净”。它将UI保留在UI中,将服务器保留在服务器中。我想那只是个口味问题。

相关问题