使用add_annotations进行R绘制无法正常工作

时间:2018-04-27 05:41:34

标签: r shiny plotly

我使用Rstudio绘制带有情节包的图片。但是有一些我无法理解的错误。

1)警告:origRenderFunc()中的警告:
忽略明确提供的小部件ID" bcc122e50b9&#34 ;; Shiny不使用它们

2)绘图对象的功能(如平移,放大,缩小,自动缩放等)可以在网络中正常运行。但是当我在Rstudio上运行R代码时。一旦我点击平移移动图片,Rstudio就会停止工作。这是我的代码或Rstudio软件中的问题吗? 您可以使用以下代码了解详细信息。

library(ggplot2)
library(plotly)
library(shiny)
positiox_positiony <- data.frame(x_position=1:2,y_position=3:4)
node_edge_xy <- data.frame(x=1,y=3,xend=2,yend=4)
ui <- shinyUI(bootstrapPage(  
  plotlyOutput(outputId = "main_plot")  
))
server = shinyServer(function(input, output) {
  output$main_plot <- renderPlotly({
    p <- ggplot(positiox_positiony,aes(x=x_position,y=y_position))+
      geom_point(color="red",size=10,alpha=0.8)+
      geom_segment(data=node_edge_xy,aes(x = x,y = y,xend = xend,yend = yend))

    ggplotly(p)%>%
      add_annotations(showarrow = T,
                      text ='',
                      arrowhead=2,
                      arrowwidth = 2,
                      arrowside = 'srart+end',
                      opacity=1,
                      x=node_edge_xy$x,y=node_edge_xy$y,
                      ax=node_edge_xy$xend,ay=node_edge_xy$yend,
                      xref = "x",yref = "y",
                      axref = "x",ayref = "y")
  })
})

shinyApp(ui,server)

有趣的是,当我选择&#39; showarrow = T&#39; to&#39; showarrow = F&#39;然后可以正常使用panly功能。

0 个答案:

没有答案