How to display large dataset on flexdashboard using crosstalk, filter_select?

203 Views Asked by At

I would like to display a map made with ggplot on a flexdashboard page. I am using crosstalk to filter the species I need and plot the corresponding map. However, the ggplotly converter seems to work, the plots are all displayed at once on the dashboard and they look rather clustered. What I would really want to have is the single plot for the species selected. Does somebody know if this is actually possible, having in mind that I have 193 species? Any comment will be appreciated.

My code looks like this:

library(flexdashboard)
library(plotly)
library(tidyverse)
library(crosstalk)
library(rnaturalearth)

species_data <- read.csv("my csv file")  

land <- ne_download(scale = 50, type = 'land', 
                    category = 'physical', returnclass = "sf")  

sd <- SharedData$new(species_data)

filter_select(
  id = "SpeciesName", #from my dataset
  label = "Select Species",
  sharedData = sd,
  group = ~SpeciesName,
  multiple = FALSE
)

map1 <- ggplot() + 
    geom_point(data = sd,
               aes(x = lonm, # longitude from my dataset
                   y = latm, #latitude from my dataset
                   colour = Year), 
               alpha = 0.8, 
               size = 2) + 
    geom_sf(data = land, fill = "grey", col = "red")  +
    facet_wrap(~ SpeciesName) + 
    theme_classic() + 
    coord_sf(xlim=c(-41,-22 ),ylim=c(-74,-75,)) + 
    ylab(expression("Latitude")) + 
    xlab(expression("Longitude")) + 
    theme(legend.position = "right", 
          legend.title = element_blank()) 

ggplotly(map1)

0

There are 0 best solutions below