使用双端范围滑块显示相关性

Bring out correlation with a double-ended range slider

我想使用双端游标滑块显示几种生物标志物之间的相关性。但是,只有第一个结束的游侠滑块有效。我该如何解决这个问题?谢谢

library(shiny)
library(corrplot)

# Dataset
df <- data.frame(BM1 = c(30, 3, 34, 57, 100, 475),
             BM2 = c(0.04, 0.9, 2, 4, 2.23, 3),
             BM3 = c(2, 3, 4, 3, 10, 42),
             BM4 = c(1, 1.1, 2, 4, 2, 3),
             BM5 = c(3000, 30, 304, 507, 1000, 4075),
             BM6 = c( 0.043, 20.9, 27, 84, 2.273, 63),
             BM7 = c(304, 32, 34, 57, 100, 4753),
             BM8 = c( 0.004, 10.9, 20, 4, 2.23, 31),
             BM9 = c(301, 13, 314, 571, 10, 47),
             BM10 = c( 0.24, 0.93, 12, 42, 23, 3000))


ui <- fluidPage(
  titlePanel("Bring out correlation between several biomarkers"),
  sidebarLayout(
    sidebarPanel(
      sliderInput(inputId = "slide0",
                  label = "Choose the number of variables",
                  min = 2, 
                  max = 10,
                  value = c(1,10),
                  step = 1
       )
      ),
    mainPanel(
      plotOutput(outputId = "pearson")
    )
  )
 )

server <- function(input, output, session) {
  output$pearson <- renderPlot({
    corr <- cor(df[,1:input$slide0], method = "pearson", use  = "pairwise.complete.obs")
    corrplot(corr, type = "lower", method = "circle", tl.col = "black", tl.srt = 45)
  })
 }

举个例子

期望值

现实

是这样的吗?

library(shiny)
library(corrplot)

# Dataset
df <- data.frame(BM1 = c(30, 3, 34, 57, 100, 475),
                 BM2 = c(0.04, 0.9, 2, 4, 2.23, 3),
                 BM3 = c(2, 3, 4, 3, 10, 42),
                 BM4 = c(1, 1.1, 2, 4, 2, 3),
                 BM5 = c(3000, 30, 304, 507, 1000, 4075),
                 BM6 = c( 0.043, 20.9, 27, 84, 2.273, 63),
                 BM7 = c(304, 32, 34, 57, 100, 4753),
                 BM8 = c( 0.004, 10.9, 20, 4, 2.23, 31),
                 BM9 = c(301, 13, 314, 571, 10, 47),
                 BM10 = c( 0.24, 0.93, 12, 42, 23, 3000))


ui <- fluidPage(
  titlePanel("Bring out correlation between several biomarkers"),
  sidebarLayout(
    sidebarPanel(
      sliderInput(inputId = "slide0",
                  label = "Choose the number of variables",
                  min = 2, 
                  max = 10,
                  value = c(1,10),
                  step = 1
      )
    ),
    mainPanel(
      plotOutput(outputId = "pearson")
    )
  )
)

server <- function(input, output, session) {
  output$pearson <- renderPlot({
    corr <- cor(df[,input$slide0[1]:input$slide0[2]], method = "pearson", use  = "pairwise.complete.obs")
    corrplot(corr, type = "lower", method = "circle", tl.col = "black", tl.srt = 45)
  })
}
shinyApp(ui=ui,server=server)