Hello, I was starting to build an app to map species distribution data. However, when I run the code it maps distribution data of...what? I have no clue, whenever I run the app in RStudio and wait for a short time a world map appears with green points on it and I have absolutely no idea what these points represent or where they may be stored at. I rewrote this code, restarted the computer, ran it in the R console, and even ran the code on a different computer, but still they are plotted. If anyone has a hint, please let me know.
Here is the code to paste into RStudio:
library(shiny)
library(maptools)
library(mapdata)
library(spocc)
ui<-fluidPage(
textInput(inputId = "spec", label = "Species name", placeholder = "enter species name here"),
plotOutput(outputId = "plotname_here")
)
server<-function(input, output) {
output$plotname_here<- renderPlot({
distribution<-function(x, y){
out<-occ(query = x, from=c("gbif"))
df<-occ2df(out)
map("world")
points(df$longitude, df$latitude, pch=19, col=y, cex=0.5)
}
distribution(input$spec, "green")
}
)
}
shinyApp(ui = ui, server = server)
However, if you type a species name into the text input (e.g Apis mellifera) the dots disappear and you get the actual distribution mapped. Clearing the type-in field makes them appear again.
Also, running only the function in a console does not by default result in these dots.
Best regards,
P