代码之家  ›  专栏  ›  技术社区  ›  Alex Yahiaoui Martinez

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

  •  0
  • Alex Yahiaoui Martinez  · 技术社区  · 6 年前

    我想用一个双端游侠滑块来显示几个生物标志物之间的相关性。但是,只有第一个结束游骑兵滑块工作。我怎样才能解决这个问题?谢谢

    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)
      })
     }
    

    期望 enter image description here

    现实 enter image description here

    1 回复  |  直到 6 年前
        1
  •  3
  •   jyjek    6 年前

    像这样的?

    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)