想要为独特(AAA,BBB,CCC)生成一个闪亮的应用程序

时间:2016-06-10 05:55:41

标签: r shiny

这是一个示例数据,其中我需要x轴=时间图和y轴=唯一值(AAA,BBB,CCC)

  library(shiny)
  library(lattice)
    data<- bcl

#sample data

AAA BBB     CCC time    value
1     1     t2        24    5.2
1     1     t2        48    10.3
1     1     t2        96    7
1     1     volume    24    6788.7
1     1     volume    48    5347
1     1     t1gd        24  1.5
1     1     t1gd        48  0
1     1     t1        24    0
1     1     t1        48    1
1     1     t1        96    2
1     2     t2        24    1.1
1     2     t2        48    1.6
1     2     t2        96    1
1     2     volume    24    8302.9
1     2     volume    48    5506
1     2     t1gd        24  0.1
1     2     t1gd        48  0
1     2     t1        24    0.8
1     2     t1        48    1.1
1     2     t1        96    1.5
1     3     t2        24    2
1     3     t2        48    3
1     3     volume    24    5218.5
1     3     volume    96    8784.6
1     3     t1gd        24  0
1     3     t1gd        96  0

x1 <- unique(data$AAA) #choices for Input AAA
x2 <- unique(data$BBB) #choices for Input BBB
x3 <- unique(data$CCC) #choices for Input CCC

她是我基于独特(AAA,BBB,CCC)制作图表的闪亮代码 用于开发闪亮应用的UI代码

 ui <- fluidPage(
      titlePanel("Sample"),
      sidebarLayout(
        sidebarPanel(
          selectInput('AAA', 'AAA',choices =x1),
          selectInput('BBB', 'BBB',choices = x2),
          selectInput('CCC', 'CCC',choice=x3
        )),
        mainPanel(
          plotOutput("coolplot")

        )
      )
    )

服务器代码

server <- function(input, output) {
      output$coolplot <- renderPlot({
    data$AAA <- input$AAA
    data$BBB <- input$BBB
    data$CCC <- input$CCC
    p <- xyplot(value~time,data=data,type="b", main="time vs value")
    print(p)
  })
}
shinyApp(ui = ui, server = server)

enter image description here

1 个答案:

答案 0 :(得分:0)

最终为独特(AAA,BBB,CCC)生成了闪亮的应用程序

ui <- fluidPage(
  titlePanel("Sample"),
  sidebarLayout(
    sidebarPanel(
      uiOutput("box1"),
      uiOutput("box2"),
      uiOutput("box3")),
    mainPanel(
      plotOutput("coolplot")

    )
  )
)

############### server interface #############

server <- function(input, output) {

output$box1 <- renderUI(selectInput("AAA","AAA",unique(data$AAA)))
output$box2 <- renderUI(selectInput("BBB","BBB",unique(data$BBB[which(data$AAA%in%input$AAA)])))
output$box3 <- renderUI(selectInput("CCC","CCC",unique(data$CCC[which(data$AAA%in%input$AAA & 
               data$BBB%in%input$BBB)])))


  output$coolplot <- renderPlot({
   fi <- data %>%
     filter(AAA %in% input$AAA,
            BBB %in% input$BBB,
            CCC %in% input$CCC)

    xyplot(value~time,fi,groups=CCC,type="b",main=paste(input$AAA),pch=19,cex=1,lyt = 2,lwd = 2)

  })

}

shinyApp(ui = ui, server = server)

enter image description here

相关问题