2016-05-30 11 views
0

私は最初のフレックスダッシュボードをまとめようとしています。 (使用しているデータの概要については、hereを参照してください)入力に応じて異なる出力を反応フレームに渡す

ダッシュボードでは、施設ごとに集計データを表示したり、個々の薬剤に分割することができます。

私がこれまで持っているコードは次のとおりです。

Inputs {.sidebar} 
----------------------------------------------------------------------- 
```{r} 
selectInput("hosp", 
     label = h4("Select hospital:"), 
     choices = list("Hospital 1" = "hosp1", 
         "Hospital 2" = "hosp2"), selected = "hosp1") 

sliderInput("dates", 
     label = h4("Select dates:"), 
     min = as.Date("2006-01-01"), max = as.Date("2015-12-01"), 
     value = c(as.Date("2006-01-01"), as.Date("2015-12-01")), 
     timeFormat = "%b-%Y") 

```` 

Row 
----------------------------------------------------------------------- 
### Usage Graph 
```{r} 
renderPlot({ 
    p <- ggplot(data = summarise(group_by(filter(usage, 
         hospital == input$hosp, date > as.Date(input$dates[1]) 
         & date < as.Date(input$dates[2])), date), 
         total = round(sum(usage))), aes(x = date, y = total)) 
    + geom_line() 

p 
}) 
``` 

これは正常に動作します - 私は病院のドロップダウンを持っているし、スライダーを使用して、日付範囲を選択することができます。

私がしたいのは、2つの異なるドロップダウンを追加することです。私はこれを行うにしようとした方法、グラフの種類(総使用量、個々の薬、薬のクラス)

を選択するためのものである:

selectInput("gtype", 
     label = h4("Select graph type:"), 
     choices = list("Total Use" = "abxa", 
         "By Class" = "abxc", 
         "By Agent" = "abxd"), selected = "abxa") 

conditionalPanel("input.gtype == 'abxd'", 
      selectInput("abagent", 
         label = h4("Select Agent:"), 
         choices = list("Amoxycillin" = "amoxycillin", 
             "Co-amoxyclav" = "amoxicillin-clavulanate", 
             "Cephazolin" = "cefazolin", 
             "Gentamicin" = "gentamicin"), selected = "cefazolin" 

これはサイドバーにうまく機能 - エージェントによって選択します」次のリストボックスに薬剤の選択肢が表示され、選択することができます。

しかし、グラフパネルの出力を変更するにはどうすればよいですか?

ユースケースごとにggplot呼び出しを少し変更する必要があります。ドロップダウンの結果に応じて異なるプロットをレンダリングする方法はありますか?

私が使用して試してみた:

conditionalPanel("input.type" == "abxa", 
    renderPlot({ plot 1 call }) 
) 
conditionalPanel("input.type" == "abxd", 
    renderPlot({ plot 2 call }) 
) 

が、これは(あなたがそれらを個別に使用している場合、私は2つのrenderPlotの呼び出しが動作することを確認しました)

サイドバーの設定に関係なく表示されてもないプロットになり前もって感謝します。

答えて

0

代わりの各プロットのための条件付きパネルをやって、単にrenderplot関数内自分のチェックを行います。

renderPlot({ 
    if(input$gtype=='abxa'){ 
    plot 1 call 
    }else if(input$gtype=='abxd'){ 
    plot 2 call 
    } 
}) 
関連する問題