ath*_*shi 16 r ggplot2 shiny plotly
我试图将ggplot对象转换为plotly并在闪亮的应用程序中显示它.但我遇到一个错误"没有适用于'plotly_build'的方法应用于类"NULL"的对象
我能够成功地将ggplot对象返回到闪亮的应用程序,
output$plot1 <- renderplot({
gp <- ggplot(data = mtcars, aes(x = disp, y = cyl)) + geom_smooth(method = lm, formula = y~x) + geom_point() + theme_gdocs()
})
Run Code Online (Sandbox Code Playgroud)
但莫名其妙地无法转换它.
我的代码看起来像这样
output$plot2 <- renderplotly({
gp <- ggplot(data = mtcars, aes(x = disp, y = cyl)) + geom_smooth(method = lm, formula = y~x) + geom_point() + theme_gdocs()
ggplotly()
})
Run Code Online (Sandbox Code Playgroud)
Bry*_*gin 21
尝试:
library(shiny)
library(ggplot2)
library(ggthemes)
library(plotly)
ui <- fluidPage(
titlePanel("Plotly"),
sidebarLayout(
sidebarPanel(),
mainPanel(
plotlyOutput("plot2"))))
server <- function(input, output) {
output$plot2 <- renderPlotly({
print(
ggplotly(
ggplot(data = mtcars, aes(x = disp, y = cyl)) + geom_smooth(method =
lm, formula = y~x) + geom_point() + theme_gdocs()))
})
}
shinyApp(ui, server)
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
11120 次 |
最近记录: |