0

I'm looking to integrate leaflet maps in my shiny app. But when I do this, I have no output printed and I receive an error in my browser console :

Uncaught TypeError: Cannot read property 'filter' of undefined
at exports.OutputBinding.shinyBinding.find (htmlwidgets.js:475)
at a (init_shiny.js:15)
at f (init_shiny.js:219)
at initShiny (init_shiny.js:283)

I am doing my app with a html ui and I am calling my plot with this code :

{{leafletOutput("leaf1")}}

Here is my server.R code :

setwd("C:/Users/Prugniaud/Google Drive/Projet R")
#Librairies
library(tidyverse)
library(ggplot2)
library(lubridate)
library(scales)
library(leaflet.extras)
library(leaflet)
library(readxl)
library(dplyr)
library(RColorBrewer)
library(gridExtra)
library(geosphere)
library(data.table)
library(shiny)

test<-as.tibble(fread("test.csv"))
train<-as.tibble(fread("train.csv"))
server <- function(input, output) {

datasetInput <- reactive({
    df<-switch(input$sltDataSet,
           sltTrain=test,
           sltTest=train)
})
   output$summary <-renderPrint(
             summary(datasetInput())
           )

   fraction <- sample_n(as.tibble(fread("train.csv")), 10000)
   pickup_longitude <- c(-73.98575)
   pickup_latitude <- c(40.74856)
   ville <- c('NYC')
   long_lat <-  data.frame(ville,pickup_longitude,pickup_latitude)
   NYC<-leaflet(data = fraction) %>%
            addProviderTiles("Esri.WorldImagery") %>%
            setView(lng =        long_lat$pickup_longitude[1],lat=long_lat$pickup_latitude[1] , zoom = 10) %>%
    addCircleMarkers(lng=~pickup_longitude, lat=~pickup_latitude,         radius = 1, fillOpacity = 0.3)

   output$leaf1<-renderLeaflet(
              NYC
   )
   leafletOutput("leaf1",width="1000px",heigh="1000px")
  }

 # Run the application 
 shinyApp(ui = htmlTemplate("TAXI/www/index.html"), server = server)

What I am doing wrong?

Stefan Becker
  • 5,695
  • 9
  • 20
  • 30
Pihk
  • 17
  • 2
  • I guess you can't have `leafletOutput` in the server as this is a UI function. But I am not sure if this solves the error as your code is not reproducible. – Wilmar van Ommeren Apr 16 '19 at 11:41
  • I don't really get what you want to say by "this is a UI function", can you clarifie? – Pihk Apr 16 '19 at 11:44
  • It's a function that you normally put in your UI. In most cases, you render data in your server and you output data in your UI. If you make your data reproducible I might be able to help a bit more. – Wilmar van Ommeren Apr 16 '19 at 11:46
  • Here is the dataset I use : https://drive.google.com/file/d/1I6x6PBh0G3LXwiSikM75jIjL8DV8MEJe/view?fbclid=IwAR2ObRHvlHqwfP3p4i3y9ob0C0MN8XJ1RRRWPzB6UGBx4aqfqw6XELXpctw and – Pihk Apr 16 '19 at 11:51
  • I still can't run your code with de dataset: https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – Wilmar van Ommeren Apr 16 '19 at 11:53
  • When I do ur reproducible file I find out what was the problem. I was calling jQuery at the end of my html ui and when I remove it , it is working ! – Pihk Apr 16 '19 at 12:10

0 Answers0