【问题标题】:Linked plots without using Shiny不使用 Shiny 的链接图
【发布时间】:2018-10-23 16:37:01
【问题描述】:

我创建了一个shiny 应用程序来显示大型数据集的相关热图。按下热图图块时,会显示相应的散点图。

但是,我需要制作几个这样的应用程序,这超出了我在 shinyapps.io 上发布的限制。我的公司不愿意升级到付费计划。我尝试使用替代方法发布应用程序,例如RInno,但无济于事(我认为应用程序太复杂了?)。

如果有人能告诉我如何单独使用plotly 而不是使用shiny,我将永远感激不尽。我相信像crosstalk 这样的东西可能是将热图图块链接到散点图的路径?

谢谢

来自here 的示例。

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)

【问题讨论】:

  • 我不太明白您想要做什么,但将您所谓的不同应用程序放在多个选项卡中难道不是解决方案吗?这样一来,您仍然只是在 shinyapp.io 中发布了一个应用程序!
  • 如何使用开源闪亮服务器托管在您自己的服务器上,然后您可以托管任意数量的应用程序,并且您没有限制使用时间。只是一个想法。托管服务器比让大家都学习新技术要便宜得多,而且你已经在 Shiny 中拥有了相当不错的应用程序
  • 按照 BertilBaron 的想法,您还可以在 Amazon Web Services (aws-EC2) 上租用服务器。安装闪亮服务器相对简单。
  • 您可以将您的应用程序包装在一个 docker 容器中并通过 shinyproxy 托管它:shinyproxy.io
  • 在 Windows 上更容易将脚本作为服务运行:将 runApp(host="0.0.0.0", port=80) 添加到您的应用程序中,将 RScript.exe 配置为目标并将您的脚本添加为一个论点来自:nssm.cc

标签: r shiny plotly interactive ggplotly


【解决方案1】:

最佳答案可能是将crosstalkflexdashboard https://rmarkdown.rstudio.com/flexdashboard/ 结合使用。

在此处可以找到同时使用两者的实时示例:http://rstudio-pubs-static.s3.amazonaws.com/209203_02f14fea3274448bbbf8d04c99c6051b.html

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

【讨论】:

    猜你喜欢
    • 2018-07-24
    • 2020-08-20
    • 2020-01-22
    • 2019-02-01
    • 1970-01-01
    • 2013-12-12
    • 2018-03-23
    • 2020-06-05
    • 1970-01-01
    相关资源
    最近更新 更多