2017-05-21 10 views
0

座標のデータフレームを含むチラシマップにマーカーを追加する際に、forループに問題があります。以下は私のコードです(あなたが最後にループのために見ることができるようにエラー「の3を必要とする 『のため』渡された4つの引数を」返し、機能していません): `リーフレットの座標のループの場合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)` 

答えて

1

私はコードがhavigだと思います各addMarkerステートメントの後に%>%ステートメントの不足の問題。 forループを削除して、次のようにすることをおすすめします。

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

ありがとうございました! – madhatter5

関連する問題