没有使用Shiny的链接图

J.C*_*Con 6 interactive r shiny plotly ggplotly

我创建了一个shiny应用程序来显示大型数据集的相关热图.按下热图贴图后,将显示相应的散点图.

但是,我需要制作其中几个应用程序,这超出了我的发布限制shinyapps.io.我的公司不愿意升级到付费计划.我尝试使用其他方法发布应用程序,如RInno无效(我认为应用程序太复杂了?).

如果有人能告诉我如何plotly单独生产同样的东西而不是shiny,我会永远感激.我相信crosstalk可能是将热图贴图链接到散点图的路径?

谢谢

这里的例子.

library(plotly)
library(shiny)

# compute a correlation matrix
correlation <- round(cor(mtcars), 3)
nms <- names(mtcars)

ui <- fluidPage(
  mainPanel(
    plotlyOutput("heat"),
    plotlyOutput("scatterplot")
  ),
  verbatimTextOutput("selection")
)

server <- function(input, output, session) {
  output$heat <- renderPlotly({
    plot_ly(x = nms, y = nms, z = correlation, 
            key = correlation, type = "heatmap", source = "heatplot") %>%
      layout(xaxis = list(title = ""), 
             yaxis = list(title = ""))
  })

  output$selection <- renderPrint({
    s <- event_data("plotly_click")
    if (length(s) == 0) {
      "Click on a cell in the heatmap to display a scatterplot"
    } else {
      cat("You selected: \n\n")
      as.list(s)
    }
  })

  output$scatterplot <- renderPlotly({
    s <- event_data("plotly_click", source = "heatplot")
    if (length(s)) {
      vars <- c(s[["x"]], s[["y"]])
      d <- setNames(mtcars[vars], c("x", "y"))
      yhat <- fitted(lm(y ~ x, data = d))
      plot_ly(d, x = ~x) %>%
        add_markers(y = ~y) %>%
        add_lines(y = ~yhat) %>%
        layout(xaxis = list(title = s[["x"]]), 
               yaxis = list(title = s[["y"]]), 
               showlegend = FALSE)
    } else {
      plotly_empty()
    }
  })

}

shinyApp(ui, server)
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

小智 1

最好的答案可能是与https://rmarkdown.rstudio.com/flexdashboard/crosstalk结合使用。flexdashboard

使用两者的实例可以在这里找到: http: //rstudio-pubs-static.s3.amazonaws.com/209203_02f14fea3274448bbbf8d04c99c6051b.html

最终结果只是一个易于共享和使用的 html 页面。根据您的示例,您不需要闪亮,并且您应该能够在该用例中使用串扰。否则,您需要跳出 R 才能获得该功能。祝你好运!