r - 不使用 Shiny 的链接图
问题描述
我创建了一个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)
解决方案
最好的答案可能是crosstalk
与flexdashboard
https://rmarkdown.rstudio.com/flexdashboard/结合使用。
在这里可以找到同时使用这两种方法的实时示例:http ://rstudio-pubs-static.s3.amazonaws.com/209203_02f14fea3274448bbbf8d04c99c6051b.html 。
最终结果只是一个易于共享和使用的 html 页面。根据您的示例,您不需要闪亮,并且您应该能够在此用例中使用串扰。否则,您需要跳出 R 才能获得该功能。祝你好运!
推荐阅读
- excel - 粘贴\返回到打开的 Excel 工作表的单元格 A1
- javascript - 如何在 JavaScript 中迭代数组
- sql - 每个分支的前三名记录
- java - 使用 POST 使用 Content-Type:application/x-www-form-urlencoded (Content-Type:application/json 工作正常)的“路由中出现意外异常”
- reactjs - React 下载以供离线使用
- jquery - 通过 CSS 根据另一个 div 调整 div 的高度
- ios - 检查特定视图控制器是否在 App 委托的前台打开
- python - 在neomodel中使用relationship_id删除neo4j节点之间的关系
- amazon-s3 - 将数据集从 GoogleCloudPlatform 导出到 AWS S3
- bash - BASH:如何查找目录中的文件数并将该数字分配为变量?