Sebastian
Sebastian

Reputation: 2570

No plot displayed with plotly in shiny

when I'm pasting the code from https://plot.ly/r/shinyapp-plotly-events/ into my console no plotly graph is diplayed, I can't get any plot in shiny displayed with plotly.

My sessionInfo:

R version 3.4.0 (2017-04-21)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

Matrix products: default

locale:
[1] LC_COLLATE=German_Germany.1252  LC_CTYPE=German_Germany.1252    LC_MONETARY=German_Germany.1252 LC_NUMERIC=C                    LC_TIME=German_Germany.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] plotly_4.7.0       ggplot2_2.2.1.9000 feather_0.3.1      RODBC_1.3-15       dplyr_0.5.0        shiny_1.0.3

Am I using the wrong package versions? I reinstalled everything from cran but i never see a plotly graph with shiny. I can produce the plotly graph's inside RStudio in the Viewer. Do I have to use any of the devtools versions of plotly/ggplot/shiny or all devtool versions? I tried plotly_4.7.0.9000 but still no output is shown.

I found a post plotly graph doesn't show up that renderPlotly({return(plot_ly(x))}) is broken, but even with renderPlotly(data) I can't produce any frames in shiny.

Example Code from the plotly gallery, the error should be in my setup I suppose, as a mater of form the code:

library(plotly)
library(shiny)

ui <- fluidPage(
  radioButtons("plotType", "Plot Type:", choices = c("ggplotly", "plotly")),
  plotlyOutput("plot"),
  verbatimTextOutput("hover"),
  verbatimTextOutput("click"),
  verbatimTextOutput("brush"),
  verbatimTextOutput("zoom")
)

server <- function(input, output, session) {

  output$plot <- renderPlotly({
    # use the key aesthetic/argument to help uniquely identify selected observations
    key <- row.names(mtcars)
    if (identical(input$plotType, "ggplotly")) {
      p <- ggplot(mtcars, aes(x = mpg, y = wt, colour = factor(vs), key = key)) + 
        geom_point()
      ggplotly(p) %>% layout(dragmode = "select")
    } else {
      plot_ly(mtcars, x = ~mpg, y = ~wt, key = ~key) %>%
        layout(dragmode = "select")
    }
  })

  output$hover <- renderPrint({
    d <- event_data("plotly_hover")
    if (is.null(d)) "Hover events appear here (unhover to clear)" else d
  })

  output$click <- renderPrint({
    d <- event_data("plotly_click")
    if (is.null(d)) "Click events appear here (double-click to clear)" else d
  })

  output$brush <- renderPrint({
    d <- event_data("plotly_selected")
    if (is.null(d)) "Click and drag events (i.e., select/lasso) appear here (double-click to clear)" else d
  })

  output$zoom <- renderPrint({
    d <- event_data("plotly_relayout")
    if (is.null(d)) "Relayout (i.e., zoom) events appear here" else d
  })

}

shinyApp(ui, server)

Any suggestions are very welcome, thanks!

Upvotes: 1

Views: 2041

Answers (1)

Sebastian
Sebastian

Reputation: 2570

Issue was hotfixed by https://github.com/ropensci/plotly/issues/1042 in the devtools version of plotly.

devtools::install_github('ropensci/plotly')

Upvotes: 1

Related Questions