R/ShinyApp 未在浏览器中显示 plot_ly 但在查看器窗格中仅显示图表

R/ShinyApp not showing plot_ly in browser but show only graph in viewer pane

我遇到了与中所述相同的问题 R/Shiny plots do not show in the browser

但在我的例子中,reactivePlot() 不是 working.It 显示

error i.e "reactivePlot is deprecated. Please use renderPlot instead."

代码没有抛出任何错误。它工作正常。问题仅在于在浏览器中显示绘图。我在所有浏览器上都试过了,图表显示在查看器窗格而不是浏览器上,尽管如果我绘制其他图表(如 barplot),它很容易显示在浏览器上。 我无法解决问题!!帮帮我!! 提前致谢!!!!

举个例子说明它是如何解决我的问题的。

ui <- dashboardPage(
  dashboardHeader(title = "Basic dashboard"),
  dashboardSidebar(),
  dashboardBody(
   fluidRow(
    box(plotlyOutput("plot1", height = "400px", width = "600px"))   
   )
  )
)
server <- function(input, output) {
set.seed(100)
d <- diamonds[sample(nrow(diamonds), 1000), ]
output$plot1 <- renderPlotly({
  plot_ly(d, x = ~carat, y = ~price, color = ~carat,
        size = ~carat, text = ~paste("Clarity: ", clarity))    
 })
}
shinyApp(ui = ui, server = server)

我使用 UI 中的 plotly() 和服务器中的 renderPlotly() 解决了这个问题。