0
我在plotly
有一些困難。我希望能夠以pdf格式下載plotly
。但是同時加入到我的一些代碼X和Y軸的參數(因爲如果我轉ggplot
到plotly
,X和Y軸的標題被切斷)GGPlotly:downloadHandler給出空圖
此代碼工作下載PDF文件:
library(shiny)
library(DT)
library(ggplot2)
library(plotly)
shinyApp(
ui = fluidPage(
fluidRow(downloadButton('downloadplot',label='Download Plot')),
plotlyOutput('plot1')
),
server = function(input, output) {
testplot <- function(){
a <- ggplot(mtcars, aes(x = interaction(cyl, carb, lex.order = T), y = mpg,fill = interaction(cyl, carb, lex.order = T))) +
geom_boxplot()
}
output$plot1 <- renderPlotly({testplot()})
output$downloadplot <- downloadHandler(
filename ="plot.pdf",
content = function(file) {
pdf(file, width=12, height=6.3)
print(testplot())
dev.off()
})})
而除了這個代碼修復ggplotly
的標題的失敗:
a <- ggplot(mtcars, aes(x = interaction(cyl, carb, lex.order = T), y = mpg,fill = interaction(cyl, carb, lex.order = T))) +
geom_boxplot()
p <- ggplotly(a + ylab(" ") + xlab(" "))
x <- list(
title = "[x]"
)
y <- list(
title = "[y]"
)
p %>% layout(xaxis = x, yaxis = y)}
給出了一個空的陰謀......
感謝您的幫助!
但是到底在哪我應該使用'回報(一)'..Than我需要if語句使用'downloadHandler' –
如果你有plotly USER_NAME等,你可以使用' plotly_IMAGE'。或者你需要使用不同的功能一個用於陰謀和一個用於pdf ggplot – Batanichek
我沒有plotli user_name。 'plotly'的問題是我不能在Internet Explorer中使用** plotly下載圖像按鈕**,這就是爲什麼唯一的解決方案是添加'downlaodHandler'這將給我的PDF文件 –