依赖于另一个selectInput的selectInput [英] selectInput that is dependent on another selectInput

查看:23
本文介绍了依赖于另一个selectInput的selectInput的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在下面有一些数据,我正在使用它们在R SHINY中创建一个甜甜圈图表,其中date是一个角色。我希望能够选择要查看其分数的电子邮件,但在第二个下拉选择中只能看到该电子邮件有活动的日期。

例如,如果我在第一个下拉列表中选择了email=xxxx,我希望在日期选择字段中只看到"无活动"。对于email=yyyy,我只希望看到6/17/14、6/18/14、6/19/14作为选项。

我在UI中尝试了一种嵌套的子集。示例:

> 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"))
+   )
+ ))

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

数据

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

我到目前为止的代码:

App.R

library(shiny)
library(shinydashboard)

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


server <- function(input, output) {
  output$distPlot <- renderPlot({
    ggplot(data = subset(dat5, (email %in% input$Select & date %in% input$User)), aes(fill=variable, ymax = ymax, ymin = ymin, xmax = 4, xmin = 3)) +
      geom_rect(colour = "grey30", show_guide = F) +
      coord_polar(theta = "y") +
      geom_text(aes(x = 0, y = 0,label = round(value[1]*100))) +
      xlim(c(0, 4)) +
      theme_bw() +
      theme(panel.grid=element_blank()) +
      theme(axis.text=element_blank()) +
      theme(axis.ticks=element_blank()) +
      xlab("") +
      ylab("") +
      scale_fill_manual(values=c('#33FF00','#CCCCCC')) 

  })
}
  shinyApp(ui = ui, server = server)

推荐答案

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

您可以在ui.R中添加:

uiOutput("secondSelection")

和您的server.R中:

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

这篇关于依赖于另一个selectInput的selectInput的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆