【发布时间】:2017-12-27 05:18:53
【问题描述】:
我尝试为我的目的改装this闪亮的应用程序。因为我想在上面添加一些文本,所以我使用 Rmd 格式。以下代码与链接中的代码完全相同,只是我删除了 server- 和 ui-functions,否则您将看不到所有输出。 (更新:我还去掉了点击、缩放和画笔事件,以使代码更具可读性)
```{r cars, echo=FALSE}
library(plotly)
library(shiny)
fluidPage(
radioButtons("plotType", "Plot Type:", choices = c("ggplotly", "plotly")),
plotlyOutput("plot", height = "700px"),
verbatimTextOutput("hover")
)
output$plot <- renderPlotly({
# use the key aesthetic/argument to help uniquely identify selected observations
key <- row.names(mtcars)
if (identical(input$plotType, "ggplotly")) {
p <- ggplot(mtcars, aes(x = mpg, y = wt, colour = factor(vs), key = key)) +
geom_point()
ggplotly(p) %>% layout(dragmode = "select")
} else {
plot_ly(mtcars, x = ~mpg, y = ~wt, key = ~key) %>%
layout(dragmode = "select")
}
})
output$hover <- renderPrint({
d <- event_data("plotly_hover")
if (is.null(d)) "Hover events appear here (unhover to clear)" else d
})
```
我将height=700px 添加到plotlyOutput,因为我的ggplot-graph 中有一个更大的数据集和一个很长的图例。然而,虽然 plotly 图调整 - ggplot-graph 不会大于〜500px。
根据this thread,这是ggplotly 的问题。问题是我需要在plotlyOutput 中设置height=700px 以阻止ggplotly-graph 过度绘制我的文本输出。 我正在搜索的是:
- 除了在
plotlyOutput中设置height=700px之外,另一种停止过度绘图的方法,或者, - 另一种更改
ggplotly-graph 大小的方法
为了实现后者,我尝试在之后将ggplotly 的高度添加到布局函数中。我什至在对应的layout 中set autosize=FALSE。我也试过specify the height in an extra renderUI-function。
【问题讨论】:
标签: r shiny r-markdown plotly