當我在ggplotly()中爲具有大量構面組的閃亮應用程序執行facet_grid時,情節會混亂。但它在Shiny之外正常工作。R:facet_wrap無法正確顯示ggplotly中的閃亮應用程序
我該如何解決這個問題?
我懷疑它是連接到Y規模,但我找不到解決方案。
下面是基於diamonds example from plotly的可重複的示例。閃亮的
比較與非閃亮輸出:Comparison of facet_grid outside and within Shiny
代碼
外閃亮:
library(ggplot2)
data(diamonds, package = "ggplot2")
# new faceting group
diamonds$rdmGroup <- as.factor(sample(LETTERS, dim(diamonds)[1], replace=TRUE))
# subset of diamonds
diamonds <- diamonds[sample(nrow(diamonds), 1000),]
ggplot(diamonds , aes_string(x = diamonds$x, y = diamonds$y, color = diamonds$x)) +
geom_point() + facet_grid(rdmGroup~.) +
guides(color=FALSE) +
labs(x = "X", y="Y")
相同的代碼在一個閃亮的應用程序:
library(shiny)
library(plotly)
library(ggplot2)
data(diamonds, package = "ggplot2")
# new faceting group
diamonds$rdmGroup <- as.factor(sample(LETTERS, dim(diamonds)[1], replace=TRUE))
# subset of diamonds
diamonds <- diamonds[sample(nrow(diamonds), 1000),]
ui <- fluidPage(
headerPanel("Diamonds Explorer"),
sidebarPanel(
sliderInput('plotHeight', 'Height of plot (in pixels)',
min = 100, max = 2000, value = 1000)
),
mainPanel(
plotlyOutput('trendPlot')
)
)
server <- function(input, output) {
output$trendPlot <- renderPlotly({
p <- ggplot(diamonds, aes_string(x = diamonds$x, y =diamonds$y, color = diamonds$x)) +
geom_point()+ facet_grid(rdmGroup~., scales = "free_y") +
labs(x = "X", y="Y")
ggplotly(p) %>%
layout(height = input$plotHeight, autosize=TRUE)
})
}
shinyApp(ui, server)
PS:)我用aes_string(而不是AES()故意,因爲我需要它在我真正的應用程序。
我運行你的例子,當獲得大量的警告。您是否嘗試安裝ggplot2的最新github版本? 「我們建議您使用GGPLOT2的開發版本'ggplotly()' 與安裝它:'devtools :: install_github( '哈德利/ GGPLOT2')'」 – DataJack
我更新GGPLOT2和警告都沒有了。感謝您的建議。但它並沒有解決這個問題。 – Jim