2016-01-21 14 views
5

私はRシャイニーでドーナツチャートを作成するために使用している以下のデータがあります。dateは文字です。私はスコアを表示したい電子メールを選択できるようにしたいが、2番目のドロップダウン選択では、その電子メールが活動している日付のみが表示されます。R別のselectInputに依存するシャープなselectInput

たとえば、最初のプルダウンで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")) 
+ ) 
+)) 

しかし、これはまだすべての可能な日付の選択

を表示DATA

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) 

答えて

8

あなたはアプリケーションの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"])) 
     }) 
+0

を!何らかの理由で、私は日付の前後に引用符を付けずに 'choices = as.character(dat5 [dat5 $ email == input $ Select、" date "])'しなければなりませんでした。そうでなければ素晴らしい仕事! – Hillary

+0

私は答えの文「あなたはアプリケーションのui.R部分の入力にアクセスできません」と混同しています。条件付きパネルを使用するときは、input.panelに基づいて条件を定義しています。これはUIの入力に依存しませんか? –

関連する問題