例として、ggplot2 に組み込まれているダイヤモンド データを使用します。
カット、色、透明度に応じてデータフレームを表示したい。ただし、控除で項目を選択したかったのです。ドロップダウンメニューで利用可能な色などを明確に選択したいと思います。
以下のメソッドは、別のアイテムを見たいときに更新されません。plyrを使用して光沢のあるこれを行う簡単な方法はありますか?
ダイヤモンドのデータフレームは最良の例ではないかもしれませんが、他のデータは見つかりません。
サーバー.R
library(plyr)
dm<-dlply(diamonds, .(cut))
for(x in 1:length(dm)){
assign(eval(parse(text = paste("names(dm)[x]"))),dm[[x]])
}
shinyServer(function(input, output) {
output$choose_cut <- renderUI({
selectInput("cut", "Cut", as.list(names(dm), multiple = TRUE))
})
output$choose_color <- renderUI({
if(is.null(input$cut)) return()
dat <- get(input$cut)
dm2<-dlply(dat, .(color))
for(x in 1:length(dm2)){
assign(eval(parse(text = paste("names(dm2)[x]"))),dm2[[x]], envir = globalenv()
)}
selectInput("color", "Color", as.list(names(dm2)))})
output$choose_clarity <- renderUI({
if(is.null(input$color)) return()
dat <- get(input$color)
dm3<-dlply(dat, .(clarity))
for(x in 1:length(dm3)){
assign(eval(parse(text = paste("names(dm3)[x]"))),dm3[[x]], envir = globalenv())
}
selectInput("clarity", "Clarity", as.list(names(dm3)))
})
output$table <- renderTable({
if (is.null(input$clarity)) return()
dat <- get(input$clarity)
dat
})
})
ui.R
shinyUI(pageWithSidebar(
headerPanel(""),
sidebarPanel(
uiOutput("choose_cut"),
uiOutput("choose_color"),
uiOutput("choose_clarity"),
br()
),
mainPanel(
"Data", tableOutput("table"))))