首页 > 解决方案 > ggcorrplot 是否有特定的服务器名称

问题描述

我在 R 闪亮的服务器输出中尝试 ggcorrplot。ggcorrplot 用于创建相关矩阵。我尝试使用 renderPlotly。输出未显示。我相信它只是因为这个。当我在 R Shiny 之外运行 ggcorrplot 时,我得到了输出。请指教。或者是否有另一种方法可以仅在 ggplot 下创建相关矩阵。我的示例数据数据框如下所示

install.packages("ggcorrplot")
library(ggcorrplot)
df
Date         Var1     Var2     Var3    Var4      
1/1/2019      12       21       34      23
1/1/2019      13       22       35      24
1/1/2019      14       22       35      25
1/1/2019      15       22       35      26

corr <- round(cor(df[2:5]),1)
ggcorrplot(corr,method = "circle",lab = TRUE,hc.order = TRUE)

当我在renderploty下使用ggcorrplot时,没有输出

标签: r

解决方案


你有两个选择:

1)为您的 ggplot 对象使用renderPlotand 2)将您的 ggplot 对象包装在其中,然后使用and调用。您的里程将非常使用此选项,因为并非 ggplot 的所有美学都被转换为情节。plotOutput
ggplotyrenderPlotlyplotlyOutput

library(ggcorrplot)
library(shiny)
library(plotly)

ui <- bootstrapPage(
  #numericInput('n', 'Number of obs', n),
  plotOutput('plot'),
  plotlyOutput('plotly')
)

# Define the server code
server <- function(input, output) {
  output$plot <- renderPlot({
    cor <- cor(matrix(rnorm(100), ncol = 10))
    ggcorrplot(cor)
  })
  output$plotly <- renderPlotly({
    cor <- cor(matrix(rnorm(100), ncol = 10))
    ggplotly(ggcorrplot(cor))
  })
}

shinyApp(ui, server)

推荐阅读