2017-05-21 4 views
0

Ich habe Probleme mit meiner for-Schleife zum Hinzufügen von Markierungen zu meiner Broschüre Karte mit einem Datenrahmen von Koordinaten. Unten ist mein Code (wie Sie die for-Schleife am Ende sehen kann funktioniert nicht, den Fehler „4 Argumente übergeben‚für‘auf die 3 erfordert“ Rückkehr): `For Schleife für Broschürenkoordinaten in R

library(shiny) 
library(shinydashboard) 
library(devtools) 
library(leaflet) 
library(DT) 
library(ggplot2) 
library(dplyr) 
library(tidyverse) 
library(heatmaply) 
library(shinyHeatmaply) 
library(markdown) 
library(ggthemes) 

r_colors <- rgb(t(col2rgb(colors())/255)) 
names(r_colors) <- colors() 

demodata <- read.csv("demodata.csv") 
colnames(demodata)[1] <- "Region" 

lpidata <- read.csv("LPIdata.csv") 

tp2data <- demodata[24:25] 


# Define UI for application that draws a histogram 
ui <- dashboardPage(
    dashboardHeader(title = "NOAA Puerto Rico Coral Data", titleWidth = 2000), 
    dashboardSidebar(sidebarMenu(
    menuItem("Visualization", tabName = "dashboard", icon = icon("line-chart")), 
    menuItem("Data", tabName = "widgets", icon = icon("table")), 
    menuItem("Map", tabName = "map", icon = icon("map-marker")), 
    selectInput(inputId = "Lucifer", "X-axis", choices = c("MAXIMUM DIAMETER", "PERPENDICULAR DIAMETER", "HEIGHT")), 
    selectInput(inputId = "lucifer", "y-axis", choices = c("HEIGHT", "PERPENDICULAR DIAMETER", "MAXIMUM DIAMETER")) 
)), 
    dashboardBody(
    tabItems(
     # First tab content 
     tabItem(tabName = "dashboard", 
       fluidRow(column(3), 
       box(plotOutput("plot5", height = 800, width = 800)))), 
     tabItem(tabName = "widgets", 
       fluidRow(
       box(dataTableOutput("dtbl"), width = "100%", height = 900, server = TRUE, div(style = 'overflow-x: scroll', DT::dataTableOutput('table'))))), 
     tabItem(tabName = "map", fluidRow(
     box(
       leafletOutput("mymap"), width = 12, height = "100%")) 
    )))) 



# Define server logic required to draw a histogram 
server <- function(input, output) { 

    output$plot5 <- renderPlot(ggplot(data = demodata) + 
           geom_smooth(mapping = aes(x = MAX_DIAMETER, y = HEIGHT), fill = "blue") + 
           xlab("Maximum Diameter") + 
           ylab("Height") + 
           theme_stata(base_size = 16)) 


    output$dtbl <- renderDataTable(demodata, width ="100%", options = list(scrollX = TRUE)) 
    latVector <- as.vector(demodata["LAT_DEGREES"]) 
    longVector<- as.vector(demodata["LON_DEGREES"]) 
    output$mymap <- renderLeaflet({ 
    leaflet() %>% 
     addTiles() %>% 
     for (i in 1:4308){ 
     addMarkers(lat = latVector[i, 1], lng = longVector[i, 1]) 
     } 






    }) 


    } 

# Run the application 
shinyApp(ui = ui, server = server)` 

Antwort

1

Ich denke, der Code havig ist Probleme mit dem Fehlen einer %>% Erklärung nach jeder addMarker Aussage. Ich würde empfehlen, die for Schleife zu entfernen und gerade zu haben:

output$mymap <- renderLeaflet({ 
    leaflet() %>% 
     addTiles() %>% 
     addMarkers(lat = latVector[1:4308, 1], lng = longVector[1:4308, 1]) 
    }) 
+0

Vielen Dank amg! – madhatter5