How to make the variables that are significant appear in the correlation plot?

Hello to everybody.
Does anyone know how to make the variables that are significant appear in the correlation plot? And that these are also different, whether they have an asterisk or a different color?

library(tidyverse)
library(corrplot)
#> corrplot 0.84 loaded
library(RColorBrewer)

metadata <- data.frame (tibble::tribble(
  ~SampleID, ~Dissolved.oxygen,   ~pH, ~Water.temperature, ~Turbidity,  ~ORP,
  "1A",              4.24,  9.94,              24.48,       87.3,    97,
  "1B",              2.58, 10.06,              24.95,       95.2, 108.4,
  "1C",              2.85,  9.98,              24.01,       98.8, 102.9,
  "1D",              3.81,  9.07,              26.67,       24.9,    94,
  "1E",              2.64,  8.99,              24.01,       43.1,  63.9,
  "1F",              4.61,  8.93,               23.5,       49.1,  64.7,
  "1G",              5.74,  9.24,              24.46,       68.6,  40.3,
  "1H",              3.69,  9.32,              24.65,       69.8,  48.1,
  "2A",              4.24,  9.94,              24.48,       87.3,    97,
  "2B",              2.66,    10,              24.92,        113, 111.9,
  "2C",              2.85,  9.98,              24.01,       98.8, 102.9,
  "2D",              3.81,  9.07,              26.67,       24.9,    94,
  "2E",              2.64,  8.99,              24.01,       43.1,  63.9,
  "2F",              4.61,  8.93,               23.5,       49.1,  64.7,
  "2G",              5.74,  9.24,              24.46,       68.6,  40.3,
  "2H",              3.69,  9.32,              24.65,       69.8,  48.1,
  "3A",              2.51, 10.04,              24.35,       87.7,  91.3,
  "3B",              2.66,    10,              24.92,        113, 111.9,
  "3C",              3.14,    10,                 24,       96.9,   108,
  "3D",              2.92,  9.06,              26.46,       39.7,  23.7,
  "3E",              1.83,  8.99,              23.99,         49,  64.1,
  "3F",              1.82,  8.92,              23.43,       47.6,  60.4,
  "3G",              3.02,  9.18,              24.14,       66.6,  40.6,
  "3H",               3.3,  9.32,              24.67,       74.1,  49.8,
  "4A",              2.51, 10.04,              24.35,       87.7,  91.3,
  "4B",              3.04,  9.96,              24.04,       98.5,  98.9,
  "4C",              2.85,  9.98,              24.01,       98.8, 102.9,
  "4D",              2.92,  9.06,              26.46,       39.7,  23.7,
  "4E",              1.83,  8.99,              23.99,         49,  64.1,
  "4F",              1.82,  8.92,              23.43,       47.6,  60.4,
  "4G",              3.02,  9.18,              24.14,       66.6,  40.6,
  "4H",               3.3,  9.32,              24.67,       74.1,  49.8,
  "5A",              4.24,  9.94,              24.48,       87.3,    97,
  "5B",              3.04,  9.96,              24.04,       98.5,  98.9,
  "5C",              2.85,  9.98,              24.01,       98.8, 102.9,
  "5D",              3.81,  9.07,              26.67,       24.9,    94,
  "5E",              2.64,  8.99,              24.01,       43.1,  63.9,
  "5F",              4.61,  8.93,               23.5,       49.1,  64.7,
  "5G",              5.74,  9.24,              24.46,       68.6,  40.3,
  "5H",              3.69,  9.32,              24.65,       69.8,  48.1,
  "6A",              4.24,  9.94,              24.48,       87.3,    97,
  "6B",              2.09,  9.95,              24.01,       95.9,  92.8,
  "6C",              2.98, 10.09,              24.36,       97.2, 106.9,
  "6D",              3.81,  9.07,              26.67,       24.9,    94,
  "6E",              1.83,  8.99,              23.99,         49,  64.1,
  "6F",              1.82,  8.92,              23.43,       47.6,  60.4,
  "6G",              3.02,  9.18,              24.14,       66.6,  40.6,
  "6H",               3.3,  9.32,              24.67,       74.1,  49.8,
  "7A",              2.51, 10.04,              24.35,       87.7,  91.3,
  "7B",              2.09,  9.95,              24.01,       95.9,  92.8,
  "7C",              2.98, 10.09,              24.36,       97.2, 106.9,
  "7D",              8.17,  9.04,              24.88,       46.9,  90.4,
  "7E",              2.63,     9,               24.7,       37.2,  74.9,
  "7F",              7.69,  9.53,              26.14,       74.2,  67.7,
  "7G",              3.07,  9.31,              24.19,       69.9,    42,
  "7H",               3.7,  9.14,              22.65,       71.3,  37.1,
  "8A",              2.51, 10.04,              24.35,       87.7,  91.3,
  "8B",              3.04,  9.96,              24.04,       98.5,  98.9,
  "8C",              2.18,  9.97,               24.4,      100.6, 102.7,
  "8D",              8.17,  9.04,              24.88,       46.9,  90.4,
  "8E",              2.63,     9,               24.7,       37.2,  74.9,
  "8F",              7.69,  9.53,              26.14,       74.2,  67.7,
  "8G",              3.07,  9.31,              24.19,       69.9,    42,
  "8H",               3.7,  9.14,              22.65,       71.3,  37.1,
  "9A",              2.58, 10.06,              24.95,       95.2, 108.4,
  "9B",              2.09,  9.95,              24.01,       95.9,  92.8,
  "9C",              2.18,  9.97,               24.4,      100.6, 102.7,
  "9D",              2.16,  8.96,               24.3,         42,    53,
  "9E",               1.7,  9.02,              24.72,       36.1,  63.4,
  "9F",               6.8,  9.51,              26.15,       74.4,  73.9,
  "9G",              1.95,  9.39,               23.9,       44.4,    42,
  "9H",              4.28,  8.85,              20.65,       71.3,  37.5,
  "10A",              2.58, 10.06,              24.95,       95.2, 108.4,
  "10B",              2.09,  9.95,              24.01,       95.9,  92.8,
  "10C",              2.98, 10.09,              24.36,       97.2, 106.9,
  "10D",              2.16,  8.96,               24.3,         42,    53,
  "10E",               1.7,  9.02,              24.72,       36.1,  63.4,
  "10F",               6.8,  9.51,              26.15,       74.4,  73.9,
  "10G",              1.95,  9.39,               23.9,       44.4,    42,
  "10H",              4.28,  8.85,              20.65,       71.3,  37.5,
  "11A",              2.66,    10,              24.92,        113, 111.9,
  "11B",              3.14,    10,                 24,       96.9,   108,
  "11C",              2.18,  9.97,               24.4,      100.6, 102.7,
  "11D",              8.17,  9.04,              24.88,       46.9,  90.4,
  "11E",              2.63,     9,               24.7,       37.2,  74.9,
  "11F",              7.69,  9.53,              26.14,       74.2,  67.7,
  "11G",              3.07,  9.31,              24.19,       69.9,    42,
  "11H",               3.7,  9.14,              22.65,       71.3,  37.1,
  "12A",              2.66,    10,              24.92,        113, 111.9,
  "12B",              3.14,    10,                 24,       96.9, 111.9,
  "12C",              2.92,  9.06,              26.46,       39.7,  23.7,
  "12D",              2.16,  8.96,               24.3,         42,    53,
  "12E",               1.7,  9.02,              24.72,       36.1,  63.4,
  "12F",               6.8,  9.51,              26.15,       74.4,  73.9,
  "12G",              1.95,  9.39,               23.9,       44.4,    42,
  "12H",              4.28,  8.85,              20.65,       71.3,  37.5
)
)
bacteria <- data.frame (tibble::tribble(
  ~SampleID, ~Phosphorus.Cycle, ~Nitrogen.Metabolism, ~Sulfur.Metabolism, ~Carbon.Metabolism,
  "1A",           706376L,              396282L,            345238L,           2031068L,
  "1B",           277793L,              176566L,            144250L,            877968L,
  "1C",           326036L,              147778L,            176659L,            780617L,
  "1D",            65648L,               79732L,             96972L,           1294702L,
  "1E",            84871L,              124084L,            112838L,           1849258L,
  "1F",            97394L,              193196L,            179296L,           2726298L,
  "1G",            17363L,               32891L,             39869L,            574727L,
  "1H",            84784L,               88313L,            149620L,           2166628L,
  "2A",           889746L,              833214L,            472577L,           3268882L,
  "2B",           550916L,              611761L,            291697L,           2025869L,
  "2C",           650481L,              589769L,            347089L,           2387685L,
  "2D",            47939L,              121432L,             72262L,           1128993L,
  "2E",           102389L,               89538L,            172961L,           2330818L,
  "2F",            45908L,               33741L,             76473L,           1210593L,
  "2G",           119387L,              129702L,            212123L,           2935133L,
  "2H",            88667L,               89886L,            172346L,           2654720L,
  "3A",           705255L,              321243L,            349230L,           1935721L,
  "3B",            55255L,               43700L,             20533L,            132062L,
  "3C",           173353L,               99864L,             82868L,            543815L,
  "3D",            24438L,               63143L,             40617L,            584987L,
  "3E",            32019L,              220041L,             63716L,            877078L,
  "3F",            29044L,               46153L,             54609L,            809489L,
  "3G",            29784L,               66227L,             53276L,            835653L,
  "3H",             4781L,               24391L,              8885L,            116960L,
  "4A",          1406272L,             1354609L,            730177L,           4931308L,
  "4B",           583641L,              461499L,            294084L,           2071482L,
  "4C",           221519L,              230437L,            126568L,            836750L,
  "4D",            53064L,               78223L,             92933L,           1476028L,
  "4E",            58855L,               84351L,            109296L,           1606014L,
  "4F",             5477L,              143665L,              6613L,            128560L,
  "4G",           127208L,               95559L,            208211L,           2718670L,
  "4H",           276920L,              274546L,            497337L,           6831554L,
  "5A",           781994L,              213414L,            275731L,           2141503L,
  "5B",           308999L,              149973L,            135998L,            883221L,
  "5C",           165574L,               49733L,             76277L,            419916L,
  "5D",            42886L,               95810L,             90506L,           1321898L,
  "5E",            92262L,               69207L,            174721L,           2161032L,
  "5F",            97660L,               89704L,            180662L,           2513291L,
  "5G",            57852L,               67108L,             87567L,           1215129L,
  "5H",            83538L,               79996L,             99517L,           1790705L,
  "6A",          1096455L,             1084116L,            607094L,           3988010L,
  "6B",          1089175L,              726302L,            503233L,           3573512L,
  "6C",           287656L,              228035L,            137700L,            974294L,
  "6D",            44735L,              149026L,             88774L,           1290426L,
  "6E",            45208L,              104655L,             83918L,           1228357L,
  "6F",            70683L,              159287L,            140308L,           2125940L,
  "6G",            57222L,               52595L,             60001L,           1186255L,
  "6H",           221749L,              139556L,            369670L,           5854843L,
  "7A",          1151282L,              543047L,            547851L,           3186633L,
  "7B",           260779L,               99796L,            133569L,            663132L,
  "7C",           427473L,              171231L,            216674L,           1153436L,
  "7D",           108219L,              192748L,            212412L,           3324049L,
  "7E",           111027L,              104380L,            181763L,           2739006L,
  "7F",           126200L,              142787L,            206723L,           2968698L,
  "7G",            21996L,               67145L,             37006L,            547162L,
  "7H",            25903L,               64817L,             29290L,            543339L,
  "8A",           870599L,              776083L,            462000L,           3095196L,
  "8B",          1330535L,             1069276L,            673384L,           4600781L,
  "8C",           346910L,              308999L,            189544L,           1279025L,
  "8D",           107766L,              139045L,            177004L,           2844506L,
  "8E",            62831L,              161888L,            118968L,           1669600L,
  "8F",           165908L,              200720L,            301172L,           4336420L,
  "8G",           116884L,              140446L,            181307L,           2567927L,
  "8H",           141509L,              168243L,            239793L,           3300384L,
  "9A",           386725L,              130624L,            171777L,            956830L,
  "9B",           697909L,              325873L,            315977L,           1959289L,
  "9C",           206324L,              102522L,             82676L,            606620L,
  "9D",           131853L,              152120L,            209759L,           3466161L,
  "9E",           218322L,              197795L,            357631L,           5066255L,
  "9F",           152981L,              195323L,            251852L,           4578779L,
  "9G",            71865L,               70050L,             69638L,           1424896L,
  "9H",            43094L,               82589L,             60671L,            828439L,
  "10A",           559030L,              363257L,            258000L,           1861177L,
  "10B",           545326L,              474890L,            286695L,           1965609L,
  "10C",           196646L,              126975L,             83666L,            610177L,
  "10D",            59365L,               58519L,            106804L,           1661891L,
  "10E",            44882L,               58481L,             79830L,           1263470L,
  "10F",            49213L,               72167L,            113992L,           1691683L,
  "10G",            23656L,               65074L,             38057L,            547790L,
  "10H",            22582L,               84747L,             38903L,            564567L,
  "11A",            90035L,               28367L,             28754L,            237166L,
  "11B",            66791L,               29835L,             26944L,            198304L,
  "11C",           432987L,              212694L,            195899L,           1218256L,
  "11D",            73651L,              139784L,            127241L,           2015734L,
  "11E",            60961L,              130216L,            121532L,           1762553L,
  "11F",            38586L,               67706L,             68608L,            914085L,
  "11G",            47430L,               37680L,             53135L,            948257L,
  "11H",            99999L,               93611L,            163120L,           2210448L,
  "12A",           983949L,              858434L,            509498L,           3585349L,
  "12B",           513091L,              433918L,            260078L,           1780176L,
  "12C",            64329L,              180572L,            141349L,           2227440L,
  "12D",           106578L,              219277L,            180396L,           2429028L,
  "12E",            63907L,               72174L,            111576L,           1520500L,
  "12F",            83397L,              120871L,            157863L,           2447590L,
  "12G",           240556L,              303696L,            411695L,           5754124L,
  "12H",           188436L,              152197L,            297374L,           4786243L
)
)
res1 <- cor.mtest(bind_cols(metadata[, -1],bacteria[, -1]), conf.level = 0.95)

corrr::correlate(bind_cols(bacteria[, -1], metadata[, -1])) %>%
  filter(rowname %in% colnames(bacteria)) %>%
  select(one_of(c("rowname", colnames(metadata)[-1]))) %>%
  as.data.frame() %>%
  column_to_rownames("rowname") %>%
  as.matrix() %>%
  corrplot::corrplot(is.corr = FALSE, p.mat = res1$p,insig = "p-value", pch.col = "white",
                     pch = "p<.05", pch.cex = .5, tl.col = "black", tl.srt = 45, method="color",col= brewer.pal (n=10, name= "PRGn"))
#> 
#> Correlation method: 'pearson'
#> Missing treated using: 'pairwise.complete.obs'

Created on 2021-07-11 by the reprex package (v0.3.0)

Hi
Generated your requirement

using kableExtra package as HTML table with color coding amber if significant p <= 0.05 and blue for not-significant

attached: impage of the output
Hope it helps

here is the code

##########################################################

library(shiny)
library(shinydashboard)  # for Dashboard
library(Rmisc)           # to calculate confidence interval
library(kableExtra)      # to handle scroll_box function
library(dplyr)           # select functions are covered in the library
library(Hmisc)           #Compute correlation matrix
library(tidyr)           # to use replace_na function
library(corrplot)
library(RColorBrewer)
library(xtable)
library(DT)              # for using %>% which works as a pipe in R code


ui <- fluidPage(
  
  uiOutput(outputId = "mcorrpvalue")
  
)

server <- function(input, output, session) {
  vmy <- reactiveValues(mydata=NULL,correlation_matrix=NULL)

    output$mcorrpvalue <- renderUI({
      fnCorrPvalueProcessing()    
      box(
        width = 12,
        height = 500,
        htmlOutput('mcorrelationwithsignif'),
        htmlOutput('mcorrpvaluetext')
        
      ) #box closure
      

  })
  
  
  metadata <- data.frame (tibble::tribble(
    ~SampleID, ~Dissolved.oxygen,   ~pH, ~Water.temperature, ~Turbidity,  ~ORP,
    "1A",              4.24,  9.94,              24.48,       87.3,    97,
    "1B",              2.58, 10.06,              24.95,       95.2, 108.4,
    "1C",              2.85,  9.98,              24.01,       98.8, 102.9,
    "1D",              3.81,  9.07,              26.67,       24.9,    94,
    "1E",              2.64,  8.99,              24.01,       43.1,  63.9,
    "1F",              4.61,  8.93,               23.5,       49.1,  64.7,
    "1G",              5.74,  9.24,              24.46,       68.6,  40.3,
    "1H",              3.69,  9.32,              24.65,       69.8,  48.1,
    "2A",              4.24,  9.94,              24.48,       87.3,    97,
    "2B",              2.66,    10,              24.92,        113, 111.9,
    "2C",              2.85,  9.98,              24.01,       98.8, 102.9,
    "2D",              3.81,  9.07,              26.67,       24.9,    94,
    "2E",              2.64,  8.99,              24.01,       43.1,  63.9,
    "2F",              4.61,  8.93,               23.5,       49.1,  64.7,
    "2G",              5.74,  9.24,              24.46,       68.6,  40.3,
    "2H",              3.69,  9.32,              24.65,       69.8,  48.1,
    "3A",              2.51, 10.04,              24.35,       87.7,  91.3,
    "3B",              2.66,    10,              24.92,        113, 111.9,
    "3C",              3.14,    10,                 24,       96.9,   108,
    "3D",              2.92,  9.06,              26.46,       39.7,  23.7,
    "3E",              1.83,  8.99,              23.99,         49,  64.1,
    "3F",              1.82,  8.92,              23.43,       47.6,  60.4,
    "3G",              3.02,  9.18,              24.14,       66.6,  40.6,
    "3H",               3.3,  9.32,              24.67,       74.1,  49.8,
    "4A",              2.51, 10.04,              24.35,       87.7,  91.3,
    "4B",              3.04,  9.96,              24.04,       98.5,  98.9,
    "4C",              2.85,  9.98,              24.01,       98.8, 102.9,
    "4D",              2.92,  9.06,              26.46,       39.7,  23.7,
    "4E",              1.83,  8.99,              23.99,         49,  64.1,
    "4F",              1.82,  8.92,              23.43,       47.6,  60.4,
    "4G",              3.02,  9.18,              24.14,       66.6,  40.6,
    "4H",               3.3,  9.32,              24.67,       74.1,  49.8,
    "5A",              4.24,  9.94,              24.48,       87.3,    97,
    "5B",              3.04,  9.96,              24.04,       98.5,  98.9,
    "5C",              2.85,  9.98,              24.01,       98.8, 102.9,
    "5D",              3.81,  9.07,              26.67,       24.9,    94,
    "5E",              2.64,  8.99,              24.01,       43.1,  63.9,
    "5F",              4.61,  8.93,               23.5,       49.1,  64.7,
    "5G",              5.74,  9.24,              24.46,       68.6,  40.3,
    "5H",              3.69,  9.32,              24.65,       69.8,  48.1,
    "6A",              4.24,  9.94,              24.48,       87.3,    97,
    "6B",              2.09,  9.95,              24.01,       95.9,  92.8,
    "6C",              2.98, 10.09,              24.36,       97.2, 106.9,
    "6D",              3.81,  9.07,              26.67,       24.9,    94,
    "6E",              1.83,  8.99,              23.99,         49,  64.1,
    "6F",              1.82,  8.92,              23.43,       47.6,  60.4,
    "6G",              3.02,  9.18,              24.14,       66.6,  40.6,
    "6H",               3.3,  9.32,              24.67,       74.1,  49.8,
    "7A",              2.51, 10.04,              24.35,       87.7,  91.3,
    "7B",              2.09,  9.95,              24.01,       95.9,  92.8,
    "7C",              2.98, 10.09,              24.36,       97.2, 106.9,
    "7D",              8.17,  9.04,              24.88,       46.9,  90.4,
    "7E",              2.63,     9,               24.7,       37.2,  74.9,
    "7F",              7.69,  9.53,              26.14,       74.2,  67.7,
    "7G",              3.07,  9.31,              24.19,       69.9,    42,
    "7H",               3.7,  9.14,              22.65,       71.3,  37.1,
    "8A",              2.51, 10.04,              24.35,       87.7,  91.3,
    "8B",              3.04,  9.96,              24.04,       98.5,  98.9,
    "8C",              2.18,  9.97,               24.4,      100.6, 102.7,
    "8D",              8.17,  9.04,              24.88,       46.9,  90.4,
    "8E",              2.63,     9,               24.7,       37.2,  74.9,
    "8F",              7.69,  9.53,              26.14,       74.2,  67.7,
    "8G",              3.07,  9.31,              24.19,       69.9,    42,
    "8H",               3.7,  9.14,              22.65,       71.3,  37.1,
    "9A",              2.58, 10.06,              24.95,       95.2, 108.4,
    "9B",              2.09,  9.95,              24.01,       95.9,  92.8,
    "9C",              2.18,  9.97,               24.4,      100.6, 102.7,
    "9D",              2.16,  8.96,               24.3,         42,    53,
    "9E",               1.7,  9.02,              24.72,       36.1,  63.4,
    "9F",               6.8,  9.51,              26.15,       74.4,  73.9,
    "9G",              1.95,  9.39,               23.9,       44.4,    42,
    "9H",              4.28,  8.85,              20.65,       71.3,  37.5,
    "10A",              2.58, 10.06,              24.95,       95.2, 108.4,
    "10B",              2.09,  9.95,              24.01,       95.9,  92.8,
    "10C",              2.98, 10.09,              24.36,       97.2, 106.9,
    "10D",              2.16,  8.96,               24.3,         42,    53,
    "10E",               1.7,  9.02,              24.72,       36.1,  63.4,
    "10F",               6.8,  9.51,              26.15,       74.4,  73.9,
    "10G",              1.95,  9.39,               23.9,       44.4,    42,
    "10H",              4.28,  8.85,              20.65,       71.3,  37.5,
    "11A",              2.66,    10,              24.92,        113, 111.9,
    "11B",              3.14,    10,                 24,       96.9,   108,
    "11C",              2.18,  9.97,               24.4,      100.6, 102.7,
    "11D",              8.17,  9.04,              24.88,       46.9,  90.4,
    "11E",              2.63,     9,               24.7,       37.2,  74.9,
    "11F",              7.69,  9.53,              26.14,       74.2,  67.7,
    "11G",              3.07,  9.31,              24.19,       69.9,    42,
    "11H",               3.7,  9.14,              22.65,       71.3,  37.1,
    "12A",              2.66,    10,              24.92,        113, 111.9,
    "12B",              3.14,    10,                 24,       96.9, 111.9,
    "12C",              2.92,  9.06,              26.46,       39.7,  23.7,
    "12D",              2.16,  8.96,               24.3,         42,    53,
    "12E",               1.7,  9.02,              24.72,       36.1,  63.4,
    "12F",               6.8,  9.51,              26.15,       74.4,  73.9,
    "12G",              1.95,  9.39,               23.9,       44.4,    42,
    "12H",              4.28,  8.85,              20.65,       71.3,  37.5
  )
  )
  bacteria <- data.frame (tibble::tribble(
    ~SampleID, ~Phosphorus.Cycle, ~Nitrogen.Metabolism, ~Sulfur.Metabolism, ~Carbon.Metabolism,
    "1A",           706376L,              396282L,            345238L,           2031068L,
    "1B",           277793L,              176566L,            144250L,            877968L,
    "1C",           326036L,              147778L,            176659L,            780617L,
    "1D",            65648L,               79732L,             96972L,           1294702L,
    "1E",            84871L,              124084L,            112838L,           1849258L,
    "1F",            97394L,              193196L,            179296L,           2726298L,
    "1G",            17363L,               32891L,             39869L,            574727L,
    "1H",            84784L,               88313L,            149620L,           2166628L,
    "2A",           889746L,              833214L,            472577L,           3268882L,
    "2B",           550916L,              611761L,            291697L,           2025869L,
    "2C",           650481L,              589769L,            347089L,           2387685L,
    "2D",            47939L,              121432L,             72262L,           1128993L,
    "2E",           102389L,               89538L,            172961L,           2330818L,
    "2F",            45908L,               33741L,             76473L,           1210593L,
    "2G",           119387L,              129702L,            212123L,           2935133L,
    "2H",            88667L,               89886L,            172346L,           2654720L,
    "3A",           705255L,              321243L,            349230L,           1935721L,
    "3B",            55255L,               43700L,             20533L,            132062L,
    "3C",           173353L,               99864L,             82868L,            543815L,
    "3D",            24438L,               63143L,             40617L,            584987L,
    "3E",            32019L,              220041L,             63716L,            877078L,
    "3F",            29044L,               46153L,             54609L,            809489L,
    "3G",            29784L,               66227L,             53276L,            835653L,
    "3H",             4781L,               24391L,              8885L,            116960L,
    "4A",          1406272L,             1354609L,            730177L,           4931308L,
    "4B",           583641L,              461499L,            294084L,           2071482L,
    "4C",           221519L,              230437L,            126568L,            836750L,
    "4D",            53064L,               78223L,             92933L,           1476028L,
    "4E",            58855L,               84351L,            109296L,           1606014L,
    "4F",             5477L,              143665L,              6613L,            128560L,
    "4G",           127208L,               95559L,            208211L,           2718670L,
    "4H",           276920L,              274546L,            497337L,           6831554L,
    "5A",           781994L,              213414L,            275731L,           2141503L,
    "5B",           308999L,              149973L,            135998L,            883221L,
    "5C",           165574L,               49733L,             76277L,            419916L,
    "5D",            42886L,               95810L,             90506L,           1321898L,
    "5E",            92262L,               69207L,            174721L,           2161032L,
    "5F",            97660L,               89704L,            180662L,           2513291L,
    "5G",            57852L,               67108L,             87567L,           1215129L,
    "5H",            83538L,               79996L,             99517L,           1790705L,
    "6A",          1096455L,             1084116L,            607094L,           3988010L,
    "6B",          1089175L,              726302L,            503233L,           3573512L,
    "6C",           287656L,              228035L,            137700L,            974294L,
    "6D",            44735L,              149026L,             88774L,           1290426L,
    "6E",            45208L,              104655L,             83918L,           1228357L,
    "6F",            70683L,              159287L,            140308L,           2125940L,
    "6G",            57222L,               52595L,             60001L,           1186255L,
    "6H",           221749L,              139556L,            369670L,           5854843L,
    "7A",          1151282L,              543047L,            547851L,           3186633L,
    "7B",           260779L,               99796L,            133569L,            663132L,
    "7C",           427473L,              171231L,            216674L,           1153436L,
    "7D",           108219L,              192748L,            212412L,           3324049L,
    "7E",           111027L,              104380L,            181763L,           2739006L,
    "7F",           126200L,              142787L,            206723L,           2968698L,
    "7G",            21996L,               67145L,             37006L,            547162L,
    "7H",            25903L,               64817L,             29290L,            543339L,
    "8A",           870599L,              776083L,            462000L,           3095196L,
    "8B",          1330535L,             1069276L,            673384L,           4600781L,
    "8C",           346910L,              308999L,            189544L,           1279025L,
    "8D",           107766L,              139045L,            177004L,           2844506L,
    "8E",            62831L,              161888L,            118968L,           1669600L,
    "8F",           165908L,              200720L,            301172L,           4336420L,
    "8G",           116884L,              140446L,            181307L,           2567927L,
    "8H",           141509L,              168243L,            239793L,           3300384L,
    "9A",           386725L,              130624L,            171777L,            956830L,
    "9B",           697909L,              325873L,            315977L,           1959289L,
    "9C",           206324L,              102522L,             82676L,            606620L,
    "9D",           131853L,              152120L,            209759L,           3466161L,
    "9E",           218322L,              197795L,            357631L,           5066255L,
    "9F",           152981L,              195323L,            251852L,           4578779L,
    "9G",            71865L,               70050L,             69638L,           1424896L,
    "9H",            43094L,               82589L,             60671L,            828439L,
    "10A",           559030L,              363257L,            258000L,           1861177L,
    "10B",           545326L,              474890L,            286695L,           1965609L,
    "10C",           196646L,              126975L,             83666L,            610177L,
    "10D",            59365L,               58519L,            106804L,           1661891L,
    "10E",            44882L,               58481L,             79830L,           1263470L,
    "10F",            49213L,               72167L,            113992L,           1691683L,
    "10G",            23656L,               65074L,             38057L,            547790L,
    "10H",            22582L,               84747L,             38903L,            564567L,
    "11A",            90035L,               28367L,             28754L,            237166L,
    "11B",            66791L,               29835L,             26944L,            198304L,
    "11C",           432987L,              212694L,            195899L,           1218256L,
    "11D",            73651L,              139784L,            127241L,           2015734L,
    "11E",            60961L,              130216L,            121532L,           1762553L,
    "11F",            38586L,               67706L,             68608L,            914085L,
    "11G",            47430L,               37680L,             53135L,            948257L,
    "11H",            99999L,               93611L,            163120L,           2210448L,
    "12A",           983949L,              858434L,            509498L,           3585349L,
    "12B",           513091L,              433918L,            260078L,           1780176L,
    "12C",            64329L,              180572L,            141349L,           2227440L,
    "12D",           106578L,              219277L,            180396L,           2429028L,
    "12E",            63907L,               72174L,            111576L,           1520500L,
    "12F",            83397L,              120871L,            157863L,           2447590L,
    "12G",           240556L,              303696L,            411695L,           5754124L,
    "12H",           188436L,              152197L,            297374L,           4786243L
  )
  )
  
  
  
  
  vmy$mydata <-data.frame(metadata[,-1],bacteria[,-1])

  
  

  
  fnCorrPvalueProcessing<- function(){
    library(xtable)
    yyCorreSign <-fncorstars(select_if(vmy$mydata, is.numeric))
    
    ################### coloring based on p value
    
    yyCorreP <- round(data.frame(vmy$correlation_matrix$P),3)  # get p-value o
    # all columns: update NA in entire dataframe with 1
    library(tidyr) # to use replace_na function
    yyCorreP <-yyCorreP %>%
      mutate_all(~replace_na(., 1))
    
    
    n<- ncol(yyCorreSign)
    tt <- names(yyCorreSign)
    for (c in tt){
      for (nn in 1:nrow(yyCorreSign)){
        yyCorreSign[nn,c]<- HTML(cell_spec(
          yyCorreSign[nn,c],format = "html", color = "black", align = "c", angle = 360,
          background = 
            if (yyCorreP[nn,c] == 1){
              "#000000" #black
            }
          else if (yyCorreP[nn,c] <= 0.05){
            "#ffbf00" #amber
          }
          else {
            "#77b5fe" #blue
          }
        )
        )
      }
    }
    ##########################
    
    
    yyCorreSign <- yyCorreSign[-1,]
    yyCorreSign <- yyCorreSign %>% dplyr::filter(rownames(yyCorreSign) %in% colnames(bacteria[,-1]))
    yyCorreSign <- yyCorreSign[,2:ncol(metadata)-1]
    
    
    yyCorreSign <- yyCorreSign %>% dplyr::filter(rownames(yyCorreSign) %in% colnames(bacteria[,-1]))
    yyCorreSign <- yyCorreSign[,2:ncol(metadata)-1]
    n<-ncol(yyCorreSign)
    msigninorms <-paste('if(p <= .001, "***") if(p <= .01, "**") if(p <= .05, "*"), if(p <= .1, ".", "    ")',"<br>",
                        "Color code: amber represents significant (<= 0.05) and blue represents NOT significant")
    
    output$mcorrelationwithsignif <- renderUI({
      HTML( kbl(yyCorreSign, escape = F,caption =HTML(paste('<h4><b>',"Correlation Matrix with Significance",'</b><h5>','<br>','Norms of Significance:',msigninorms)),linesep = "\\addlinespace",
                table.attr = "style='width:30%;'")%>%
              kable_styling(font_size = 14, position = "center", html_font = "Cambria",fixed_thead = T) %>%
              kable_paper("striped", full_width = F) %>%
              column_spec(c(1), color = "white",background = '#a9a9a9')%>%
              row_spec(0, angle = 360,bold=TRUE)%>%
              column_spec((1), bold = F,border_left = TRUE,border_right = TRUE,width = "1.5in") %>%
              column_spec((2:n+1), bold = F,border_left = TRUE,border_right = TRUE,width = "1.75in") %>%
              scroll_box(width = "100%", height = "350px")
      )
      
    })
    
    yyCorreP <- yyCorreP[-1,]
    yyCorreP <- yyCorreP %>% dplyr::filter(rownames(yyCorreP) %in% colnames(bacteria[,-1]))
    yyCorreP <- yyCorreP[,2:ncol(metadata)-1]
    
    
    yyCorreP <- yyCorreP %>% dplyr::filter(rownames(yyCorreP) %in% colnames(bacteria[,-1]))
    yyCorreP <- yyCorreP[,2:ncol(metadata)-1]
    
    n<- ncol(yyCorreP)
    tt <- names(dplyr::select_if(yyCorreP,is.numeric))
    for (c in tt){
      for (nn in 1:nrow(yyCorreP)){
        yyCorreP[nn,c]<- HTML(cell_spec(
          yyCorreP[nn,c],format = "html", color = "black", align = "c", angle = 360,
          background = 
            if (yyCorreP[nn,c] == 1){
              "#000000" #black
            }
          else if (yyCorreP[nn,c] <= 0.05){
            "#ffbf00" #amber
          }
          else {
            "#77b5fe" #blue
          }
        )
        )
      }
    }
    
    output$mcorrpvaluetext <- renderUI({
      HTML( kbl(yyCorreP, escape = F,caption =HTML(paste('<h4><b>',"P-Value Matrix",'</b><h5>')),linesep = "\\addlinespace",
                table.attr = "style='width:30%;'")%>%
              kable_styling(font_size = 14, position = "center", html_font = "Cambria",fixed_thead = T) %>%
              kable_paper("striped", full_width = F) %>%
              column_spec(c(1), color = "white",background = '#a9a9a9')%>%
              row_spec(0, angle = 360,bold=TRUE)%>%
              column_spec((1), bold = F,border_left = TRUE,border_right = TRUE,width = "1.5in") %>%
              column_spec((2:n+1), bold = F,border_left = TRUE,border_right = TRUE,width = "1.75in") %>%
              scroll_box(width = "100%", height = "300px")
      )
    })
    
  }
  

  fncorstars <-function(x, method=c("pearson", "spearman"), removeTriangle=c("upper", "lower"),
                        result=c("none", "html", "latex")){
    #Compute correlation matrix
    x <- as.matrix(x)
    vmy$correlation_matrix<-rcorr(x, type=method[1])
    
    R <- vmy$correlation_matrix$r # Matrix of correlation coeficients
    p <- vmy$correlation_matrix$P # Matrix of p-value 
    
    
    ## Define notions for significance levels; spacing is important.
    mystars <- ifelse(p <= .001, "***", ifelse(p <= .01, "** ", ifelse(p <= .05, "*  ", ifelse(p <= .1, ".  ", "    "))))
    
    
    ## trunctuate the correlation matrix to two decimal
    R <- format(round(cbind(rep(-1.11, ncol(x)), R), 2))[,-1]
    
    ## build a new matrix that includes the correlations with their apropriate stars
    Rnew <- matrix(paste(R, mystars, sep=""), ncol=ncol(x))
    diag(Rnew) <- paste(diag(R), " ", sep="")
    rownames(Rnew) <- colnames(x)
    colnames(Rnew) <- paste(colnames(x), "", sep="")
    
    ## remove upper triangle of correlation matrix
    if(removeTriangle[1]=="upper"){
      Rnew <- as.matrix(Rnew)
      Rnew[upper.tri(Rnew, diag = TRUE)] <- ""
      Rnew <- as.data.frame(Rnew)
    }
    
    ## remove lower triangle of correlation matrix
    else if(removeTriangle[1]=="lower"){
      Rnew <- as.matrix(Rnew)
      Rnew[lower.tri(Rnew, diag = TRUE)] <- ""
      Rnew <- as.data.frame(Rnew)
    }
    
    ## remove last column and return the correlation matrix
    # Rnew <- cbind(Rnew[1:length(Rnew)-1]) ## GP removed to tally rows and columns same length
    if (result[1]=="none") return(Rnew)
    else{
      if(result[1]=="html") print(xtable(Rnew), type="html")
      else print(xtable(Rnew), type="latex") 
    }
  }
  
 
}

shinyApp(ui, server)
1 Like

Thank you so much!!!!!

Hi
kindly have a look at my YouTube channel on Correlation Analysis. it is so flexible, you could upload any of your dataset and analyze it. you could download R script from Github link provided in the description of the video

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.