This is my code and the for loop is giving me the error: 4 arguments passed to for
which requires 3. and I tried to move the loop to include all the leaflet but still same error.
library(shiny)
library(rgdal)
library(DT)
library(dygraphs)
library(xts)
library(leaflet)
library(igraph)
library(RMySQL)
library(DBI)
library(magrittr)
#creat connection to database
con <- dbConnect(RMySQL::MySQL(), user = "root", pass = "",
servername = "localhost", db = "brest")
#dbListTables(con)
#dbListFields(con, "nodes")
r_colors <- rgb(t(col2rgb(colors()) / 255))
names(r_colors) <- colors()
ui <- fluidPage(
titlePanel(p("Maritime Map", style = "color:#3474A7")),
tabPanel("Reactive Map",
#SideBarLayout for sidebar Panel for the options of the map
sidebarLayout(
#SideBar Panel with options to adjust the map
sidebarPanel(
),
#Main panel to put plots
mainPanel(leafletOutput("map", height = 600))
)
)
)
server <- function(input, output, session) {
#select all nodes table
rs = dbSendQuery(con, "SELECT * FROM nodes")
datas = fetch(rs, n=6)
dbClearResult(dbListResults(con)[[1]])
#select all edges table
ed = dbSendQuery(con, "SELECT * FROM edge")
edg = fetch(ed, n=-1)
dbClearResult(dbListResults(con)[[1]])
#select edge_id from table edge
edid = dbSendQuery(con, "SELECT edge_id FROM edge")
edgid = fetch(edid, n=-1)
dbClearResult(dbListResults(con)[[1]])
#get number of rows in table edge
numr = dbSendQuery(con, "SELECT COUNT(*) FROM edge")
numm = fetch(numr, n=-1)
nmb <- as.numeric(numm)
pall <- colorFactor(c("navy", "red", "green", "yellow"),
domain = c("port", "anchorage", "turningpoint", "marina"))
output$map <- renderLeaflet({
leaflet() %>%
addProviderTiles(providers$Esri.OceanBasemap,
options = providerTileOptions(noWrap = TRUE)) %>%
addCircleMarkers(data = datas, weight = 3, radius= 10, color = ~pall(node_type), group = "detail",
stroke = F, fillOpacity = 0.5, clusterOptions = markerClusterOptions()) %>%
This is the for loop. when including all the leaflet in the loop I get the
error: invalid (NULL) left side of assignment.
for (i in 1:nmb) {
#select source node
src = dbSendQuery(con, "SELECT source_node_id FROM edge WHERE edge_id = 'i'")
srcc = fetch(src, n=-1)
srid <- as.numeric(srcc)
dbClearResult(dbListResults(con)[[1]])
#select longitude and latitude of source node
slonlat1 = dbSendQuery(con, "SELECT lon, lat FROM nodes WHERE node_id = 'srid'")
slonlat2 = fetch(slonlat1, n=-1)
dbClearResult(dbListResults(con)[[1]])
#select target node
tar = dbSendQuery(con, "SELECT target_node_id FROM edge WHERE edge_id = 'i'")
tarr = fetch(tar, n=-1)
trid <- as.numeric(tarr)
dbClearResult(dbListResults(con)[[1]])
#select longitude and latitude of target node
tlonlat1 = dbSendQuery(con, "SELECT lon, lat FROM nodes WHERE node_id = 'trid'")
tlonlat2 = fetch(tlonlat1, n=-1)
dbClearResult(dbListResults(con)[[1]])
dd <- data.frame(x=slonlat2, y=tlonlat2)
# addPolylines(data = dd, lng = ~lon, lat = ~lat)
}
groupOptions("details", zoomLevels = 10:30) %>%
addLegend("bottomright", colors= c("green", "navy", "yellow", "red"),
labels=c("port", "anchorage", "turningpoint", "marina"), title="Maritime")
})
}
shinyApp(ui, server)
thanks for your help
Comments
Post a Comment