1

I have created an interactive ggplot map using the girafe function with the below code

A<-ggplot(data)+geom_sf_interactive(aes(fill=Pop_Rate,tooltip = sprintf("%s<br/>%s", Region,Pop_Rate)))

girafe(code, ggobj = A,
                  options = list(opts_tooltip(use_fill = TRUE),
                                 opts_zoom(min = 1, max = 5),opts_toolbar(saveaspng = FALSE)))

When I add this code to an R markdown flexidashboard, the output includes output from the r console as well as the map

Reading layer Counties_and_Unitary_Authorities__April_2019__Boundaries_EW_BUC' from data source C:\Users\qrs19x\OneDrive - Ministry of Justice\Documents\R\Maps\Shapes\Counties_and_Unitary_Authorities__April_2019__Boundaries_EW_BUC.shp' using driver `ESRI Shapefile' Simple feature collection with 173 features and 10 fields Geometry type: MULTIPOLYGON Dimension: XY Bounding box: xmin: 86999.8 ymin: 7054.1 xmax: 655644.8 ymax: 657548.1 Projected CRS: OSGB 1936 / British National Grid

I tried results=FALSE but this also hides my "hide" to my chart. currently using the following

```{r, echo=FALSE, message=FALSE, warning=FALSE}
camille
  • 16,432
  • 18
  • 38
  • 60
Nick Read
  • 53
  • 2
  • 1
    Does this answer your question? [suppress console output in r markdown, but keep plot](https://stackoverflow.com/questions/30810476/suppress-console-output-in-r-markdown-but-keep-plot) – divibisan Jan 27 '22 at 16:15
  • I had previously seen this answer but unfortunately it did not work, I think because I am displaying chart as html widget – Nick Read Jan 27 '22 at 19:46

1 Answers1

1

I am not getting the same output as you are, in that I get no output at all when coded as you did. That being said, I don't have your data or what options you may have declared in your YAML or chunk options.

I'm curious as to what code is doing in your code. As I understand it, you have either code or ggobj, not both.

```{r giraffeMe,echo=F}

library(ggplot2)
library(ggiraph)

nc <- sf::st_read(system.file("shape/nc.shp", package = "sf"), quiet = TRUE)

gg <- ggplot(nc) + 
  geom_sf_interactive(aes(fill = AREA, 
                          tooltip = NAME, 
                          data_id = NAME))
girafe(ggobj = gg,
       options = list(opts_tooltip(use_fill = TRUE),
                      opts_toolbar(saveaspng = FALSE)))
```

This is the map rendered in the dashboard. I hovered so you could see the tooltip.

enter image description here

Kat
  • 15,669
  • 3
  • 18
  • 51