R Shiny:如何点击UpSet plot&s; s条并查看数据行

时间:2017-05-27 18:43:24

标签: r shiny

我在R中使用镦粗功能绘制交叉点。我希望能够点击翻转图中的条形图,并查看数据行。以下代码片段描述了我的Shiny应用程序。

UI

library("shiny")
library("ggplot2")
library("gridExtra")
library("plyr")
library("UpSetR")

shinyUI(
    fluidPage(
        titlePanel("Insurance Analytics"),
        sidebarLayout(
            sidebarPanel(
                dateRangeInput(inputId="hfa_period", label=h5("Select Analysis Period"), start= min(nd3$Date) , end = max(nd3$Date)) ,
                selectizeInput(inputId="hfa_provider", label = h5("Select Provider"), 
                               choices = c("ALL", as.character(unique(nd3$Provider))), multiple = TRUE, selected = ""),
                selectizeInput(inputId="hfa_gender", label = h5("Select Gender"), choices = c("ALL",as.character(unique(nd3$Sex))), multiple = TRUE, selected = ""),
                selectizeInput(inputId="hfa_Race", label = h5("Select Race"), choices = c("ALL", as.character(unique(nd3$Race))), multiple = TRUE, selected = ""),
                selectizeInput(inputId="hfa_Agerange", label = h5("Select Age Range"), choices = c("ALL", as.character(sort(unique(nd3$`Age Range`)))), multiple = TRUE, selected = "")),
            mainPanel(
                plotOutput("hfa_upsetplot"),
                dataTableOutput("hfa_dataset")
            )
        )
    )
)

服务器

function(input, output) {   

    getDataFrame <- reactive({

        if (!is.null(input$hfa_period)) {
            # Get the dates to perform query
            nd3 <- nd3[nd3$Date %in% seq.Date(input$hfa_period[1], 
                                              input$hfa_period[2], by = "days"),]
        }
        else nd3 <- nd3 

        if (!is.null(input$hfa_provider) && input$hfa_provider != "ALL") {
            nd3 <- subset(nd3, nd3$Provider %in% input$hfa_provider)
        }
        else nd3 <- nd3

        if (!is.null(input$hfa_gender) && input$hfa_gender != "ALL") {
            nd3 <- nd3 <- subset(nd3, nd3$Sex %in% input$hfa_gender)
        }
        else nd3 <- nd3

        if (!is.null(input$hfa_Race) && input$hfa_Race != "ALL") {
            nd3 <- subset(nd3, nd3$Race %in% input$hfa_Race)
        }
        else nd3 <- nd3

        if (!is.null(input$hfa_Agerange) && input$hfa_Agerange != "ALL") {
            nd3 <- subset(nd3, nd3$`Age Range` %in% input$hfa_Agerange)
        }
        else nd3 <- nd3

    })

    output$hfa_dataset <- renderDataTable({getDataFrame()}, filter = 'top', 
                                          rownames = FALSE)

    output$hfa_upsetplot <- renderPlot(upset(
        getDataFrame(), sets=c("NCC_NACC", "NATC_NAATC", "Chloroform","Benzene"),
        keep.order = TRUE, point.size=2, sets.x.label = "PATIENTS OUT OF TOTAL",
        mainbar.y.label="PATIENT COUNT BY GROUP", text.scale=1.5, line.size = 0.5, matrix.color= "mediumblue",
        main.bar.color= "royalblue2",sets.bar.color="limegreen", shade.color= "orange1", shade.alpha= 0.4))

}

0 个答案:

没有答案