Black Lives Matter. Please consider donating to Black Girls Code today.

Ggplotly: Plot not showing in RStudio or Shiny


Recently I’ve been trying to create a map for my Shiny Dashboard, and everything went fine with ggplot2. But I want to make my map interactive, so I’ve been reading about ggplotly and how everyone says it’s such a simple way to switch from ggplot to plotly.

After using ggplotly, my map was not appearing in RStudio viewer or Shiny dashboard, but didn’t generate any errors either. Apparently the map is being plotted but it can be viewed ONLY when you choose to view it in a separate window from RStudio.

I thought that my syntax is wrong, and when I asked somebody for advice, he said that it works fine for him (he uses R version 3.5.0 , plotly_4.7.1.9000 ggplot2_2.2.1.9000 while I have R version 3.5.1., plotly v.4.8.0 and ggplot2 v 3.0.0.).
I immediately tried alot of options to fix this: installed plotly v4.7.1. and ggplot2 v.2.2.1. from CRAN (this worked for a bit. After i ran ggplotly, it showed the map both in the viewer and in shiny but shortly after something went wrong, i was asked to update shiny package and to use the dev version of ggplot2), i updated to dev versions to both ggplot & plotly, i tried to use R version 3.5.0 but there were alot of incompatibilities with other packages and now I am back to where I started.

I cannot figure out what is the main problem, or how can I combine the packages versions to make this work… and also why ggplotly does not work with the newest packages. Did somebody encountered this problem before?

Any help is highly appreciated! Thank you!

My code:




          sidebarSearchForm(textId = "searchbar", buttonId = "searchbtn", label = "Search..."),
          menuItem("Test", tabName="state", icon = icon("dashboard")))


                    box(title = "Products across the country", width = 12, status = "success", plotlyOutput("map01"))



shinyServer(function(input, output) {

  world_map <- map_data("world")%>%filter(region=="Portugal")

  info = data.frame(read.csv("cities.csv", header = TRUE))

  structure(list(name = structure(c(4L, 10L, 6L, 15L, 14L, 9L, 
  3L, 7L, 8L, 11L, 18L, 17L, 1L, 16L, 12L, 13L, 2L, 19L, 5L, 20L, 
  21L), .Label = c("Continente ID0912 - Espinho", "Continente ID8234 - 
  Guimaraes", "Continente ID9912 - Braga", "Continente ID9932 - Albufeira", 
  "Jumbo ID2441 - Lisbon", "Minipreco ID1120 - Almada", "Minipreco ID1150 - 
  "Minipreco ID1212 - Canelas", "Minipreco ID1231 - Beja", "Minipreco ID1332 
  - Alfena", "Minipreco ID5345 - Caparica", "Minipreco ID7772 - Fatima", 
  "Minipreco ID8723 - Gondomar", 
  "Minipreco ID8891 - Aveiro", "Pingodoce ID1002 - Amadora", "Pingodoce 
  ID4228 - Faro", "Pingodoce ID4778 - Cova da Piedade", "Pingodoce ID5426 - 
  Coimbra", "Pingodoce ID7734 - Lagos", "Pingodoce ID7734 - Nazare", 
  "Pingodoce ID9832 - Viana do Castelo"), class = "factor"), products = 
  c(86L, 53L, 77L, 89L, 61L, 65L, 60L, 43L, 72L, 34L, 41L, 88L, 44L, 23L, 
  67L, 87L, 45L, 56L, 19L, 
  87L, 53L), lat = c(37.09, 41.23, 38.68, 38.75, 40.65, 38.02, 
  41.55, 38.68, 41.08, 38.67, 40.22, 38.67, 41.01, 37.03, 39.62, 
  41.15, 41.44, 37.1, 38.72, 39.6, 41.71), long = c(-8.26, -8.52, 
  -9.16, -9.24, -8.66, -7.86, -8.43, -9.14, -8.59, -9.19, -8.43, 
  -9.15, -8.64, -7.94, -8.64, -8.52, -8.3, -8.68, -9.14, -9.06, 
  -8.83)), class = "data.frame", row.names = c(NA, -21L))

  output$map01<- renderPlotly({
    p = info %>% ggplot() + geom_polygon(data=world_map, aes(x=long, y=lat, group=group), fill="grey50", alpha=0.3) + geom_point(aes(x=long, y=lat, colour=products, size=products, group=name), alpha=0.6) + scale_size_continuous(range=c(1,10)) + theme_void() + coord_map() + guides(size=FALSE)
    ggplotly(p, tooltip = c("group","colour"))


I am having the same problem! Please let me know if you figure anything out.