Correlation matrix of 2 datasets in shiny app

312 views
Skip to first unread message

euthymios kasvikis

unread,
Sep 28, 2017, 8:34:11 AM9/28/17
to Shiny - Web Framework for R
i want to create a shiny app which will give user the opportunity to load two datasets in csv form and automatically create their correlation coefficient matrix after selecting variables from each one. Another thought may be to run log regression. The problem is that i do not know if this method is generally accepted as correlation matrix or any other correlation method is used only in the same dataset. One thought may be to unite the two datasets into one and the run the correlation.But is this correct? Any suggestions? Below is the app until now.

#ui.r

library(shiny)




ui <- navbarPage(
  title = "Multiple Correlation App",
 
  tabPanel("Data Import",
           sidebarLayout(
             sidebarPanel(
               fileInput(
                 'file1',
                 'Dataset 1: Choose CSV File to upload',
                 accept = c('text/csv',
                            'text/comma-separated-values,text/plain',
                            '.csv')
               ),
               helpText(
                 "Note: Please ensure that the the file is in .csv",
                 "format and contains headers."
               ),
               tags$hr(),
               actionButton("do", "Import"),
               fileInput(
                 'file2',
                 'Dataset 2: Choose CSV File to upload',
                 accept = c('text/csv',
                            'text/comma-separated-values,text/plain',
                            '.csv')
               ),
               helpText(
                 "Note: Please ensure that the the file is in .csv",
                 "format and contains headers."
               ),
               tags$hr(),
               actionButton("do2", "Import")
               
               
               
             ),
             mainPanel(
               tabsetPanel(type="tab",
                           tabPanel("DATASET 1",
                                    tabsetPanel(
                                      tabPanel("Data Table",
                                              uiOutput("dt1")),
                                      tabPanel("Descriptive Statistics",
                                               verbatimTextOutput('contents'))
                                    )),
                           tabPanel("DATASET 2",
                                    tabsetPanel(
                                    tabPanel("Data Table",
                                                uiOutput("dt2")),
                                    tabPanel("Descriptive Statistics",
                                             verbatimTextOutput('contents2'))))
                                   
               
               ))
             )
           ),
  #tabpanel
  tabPanel("Correlation & Report",
           sidebarLayout(sidebarPanel(
             uiOutput("var1_select"),
             uiOutput("rest_var_select")
           ),
                         
                         mainPanel(helpText("Your Selected variables"),
                                   verbatimTextOutput("other_val_show")))#tabpanel
 
))

#server.r
server <- function(input, output) {
  hr
= eventReactive(input$do, {
    inFile
<- input$file1
   
   
if (is.null(inFile))
     
return(NULL)
   
    hr
= read.csv(inFile$datapath, header = T, sep = ",")
 
})
  hr2
= eventReactive(input$do2, {
    inFile2
<- input$file2
   
   
if (is.null(inFile2))
     
return(NULL)
   
    hr2
= read.csv(inFile2$datapath, header = T, sep = ",")
 
})
  output$table
<- renderDataTable({
   
if(is.null(hr())){return ()}
    hr
()
 
})
  output$table2
<- renderDataTable({
   
if(is.null(hr2())){return ()}
    hr2
()
 
})
  output$dt1
<- renderUI({
    dataTableOutput
("table")
 
})
  output$dt2
<- renderUI({
    dataTableOutput
("table2")
 
})
  output$contents
<- renderPrint({
   
return(summary(hr()))
 
})
  output$contents2
<- renderPrint({
   
return(summary(hr2()))
 
})
 
  output$var1_select
<-renderUI({
    selectInput
("ind_var_select","Select Dataset 1 Variables", choices =as.list(names(hr())),multiple = TRUE)
 
})
 
  output$rest_var_select
<-renderUI({
    selectInput
("other_var_select","Select Dataset 2 Variables",choices =as.list(names(hr2())),multiple = TRUE)
 
})
 
  output$other_val_show
<-renderPrint({
    cor
.test(as.numeric(input$ind_var_select),as.numeric(input$other_var_select),method="pearson",use = "complete.obs")
   
 
})
 
}

Reply all
Reply to author
Forward
0 new messages