【问题标题】:ERROR: invalid 'type' (list) of argument错误:参数的“类型”(列表)无效
【发布时间】:2018-12-01 20:54:50
【问题描述】:

如果我只是运行传单部分。它给出了一个输出,但在闪亮的应用程序中它给出了上述错误。

当我尝试从 addCircleMarkers 中删除代码时,它会给出一个没有任何标记的输出。我猜那个特定的陈述有问题。

另外,我想为每种类型更改传单中的标记形状,但这又是我在互联网上找到的资源中没有的东西。它表明我必须手动查找链接(我需要将近 10 个链接)

data('zipcode')


#removing the extra empty column
data$X <- NULL

#cleaning the zipcodes
data$ZIP.CODE <- clean.zipcodes(data$ZIP.CODE)

#adding the Stage2/Stage1 column
combine$ratio <- combine$Stage2/combine$Stage1
combine <- merge(data, zipcode,  by.x='ZIP.CODE', by.y='zip')
combine[is.na(combine)] <- 0


ui<-fluidPage(
  sidebarLayout(
    sidebarPanel(
      selectInput('rank','Ziprank',choices=levels(combine$ZIP.RANK),multiple=T,selected = 'A'),
      selectInput('type','Ziptype',choices=levels(combine$TYPE),multiple=T,selected = 'PUBLIC'),
      selectInput('market','Market',choices=c(1,2,3,4),multiple=T,selected = 1),
      selectInput('housevalue','Median Housing Value',choices=levels(combine$MEDIAN.HOUSING.VALUE),multiple=T,selected = '1HVL'),
      selectInput('familyincome','Median Family Value',choices=levels(combine$MEDIAN.FAMILY.INCOME),multiple=T,selected = '1MFI'),
      selectInput('buyingpower','Median House Buying Power',choices=levels(combine$MEDIAN.HOUSE.BUYING.POWER),multiple=T,selected = '1MHB'),
      selectInput('ethnicity','Ethnicity',choices=levels(combine$ETHNICITY),multiple=T,selected = '1ETH'),
      selectInput('population','Population Density',choices=levels(combine$POPULATION.DENSITY),multiple=T,selected = '1POP'),
      selectInput('masters','Masters Degree',choices=levels(combine$MASTERS.DEGREE),multiple=T,selected = '1MDG'),
      selectInput('associate','Associate Degree',choices=levels(combine$ASSOCIATES.DEGREE),multiple=T,selected = '1ADG'),
      selectInput('highschool','High School Age Population',choices=levels(combine$HIGH.SCHOOL.AGE.POPULATION),multiple=T,selected = '1HSP'),
      selectInput('epscode','EPS code',choices=levels(combine$EPS.CODE),multiple=T,selected = 'MS01'),
      selectInput('state','State',choices=unique(combine$state),multiple=T,selected = 'NY'),
      sliderInput('score','Zipscore', min(combine$ZIP.SCORE), max(combine$ZIP.SCORE), value=c(0.1,0.3))
    ),
    mainPanel(
      leafletOutput('plot')
    )
  )
)
server <- function(input, output) {
  output$plot <-renderLeaflet({
    final <- subset(combine, ZIP.RANK %in% input$rank &
                    TYPE %in% input$type &
                    MARKET %in% input$market &
                    MEDIAN.HOUSING.VALUE  %in% input$housevalue &
                    MEDIAN.FAMILY.INCOME %in% input$familyincome &
                    MEDIAN.HOUSE.BUYING.POWER %in% input$buyingpower &
                    ETHNICITY %in% input$ethnicity &
                    POPULATION.DENSITY %in% input$population & 
                    MASTERS.DEGREE %in% input$masters &
                    ASSOCIATES.DEGREE %in% input$associate & 
                    HIGH.SCHOOL.AGE.POPULATION %in% input$highschool &
                    EPS.CODE  %in% input$epscode &
                    state %in% input$state &
                    ZIP.SCORE >= input$score[1] & ZIP.SCORE <= input$score[2]
                    )
    pal <- colorNumeric(palette = "Reds", domain = c(0:1))
    p <- final %>%
      leaflet() %>% 
      addProviderTiles('CartoDB') %>%
      addCircleMarkers(data = final, color = ~pal(ZIP.SCORE),label=~GEONAME) %>%
      addLegend(title = "ZipScore", pal = pal, values = c(0:1), 
                position = "bottomright")
    p
  })
}

shinyApp(ui = ui, server = server)

【问题讨论】:

    标签: r shiny leaflet


    【解决方案1】:

    您需要通过leafletProxy() 添加您的圆圈标记。在我看来,你应该用以下方式重写你的代码。将您的 pal 声明放在您的 ui 上方。将您用final 引用的所有数据子集包装在它自己的reactive({}) 函数中。然后您可以在基本调用output$Plot 中添加您的leaflet()。您可以通过observe() 使用自己的观察者更新用户输入,并使用传单自己的更新功能leafletProxy() 引用用户输入

    pal <- colorNumeric(palette = "Reds", domain = c(0:1))
    server <- function(input, output) {
    
    final <- reactive({
    data_subset <- subset(combine, ZIP.RANK %in% input$rank &
                            TYPE %in% input$type &
                            MARKET %in% input$market &
                            MEDIAN.HOUSING.VALUE  %in% input$housevalue &
                            MEDIAN.FAMILY.INCOME %in% input$familyincome &
                            MEDIAN.HOUSE.BUYING.POWER %in% input$buyingpower &
                            ETHNICITY %in% input$ethnicity &
                            POPULATION.DENSITY %in% input$population & 
                            MASTERS.DEGREE %in% input$masters &
                            ASSOCIATES.DEGREE %in% input$associate & 
                            HIGH.SCHOOL.AGE.POPULATION %in% input$highschool &
                            EPS.CODE  %in% input$epscode &
                            state %in% input$state &
                            ZIP.SCORE >= input$score[1] & ZIP.SCORE <=   input$score[2])
     })
    
    
      })
     output$plot <-renderLeaflet({
      leaflet(data = combine) %>% 
      addProviderTiles('CartoDB')
    })
    
    observe({
    leafletProxy("plot", data = final() %>%
                   addCircleMarkers(color = ~pal(final()$ZIP.SCORE),     label=~final()$GEONAME) %>%
                   addLegend(title = "ZipScore", pal = pal, values = c(0:1), 
                             position = "bottomright")
    
     })
    }
    

    【讨论】:

    • 应用程序一运行就一直崩溃。我更新了我的 r 和我的包,但它仍然无法运行。现在错误是[没有可用的堆栈跟踪]
    【解决方案2】:

    不幸的是,我无法重现您的示例:不知道您从哪里获取“邮政编码”数据,也找不到 clean.zipcodes() (包“zipcode”可能是来源,但不再在 CRAN 上......)

    但是,我遇到了类似的问题,这就是我目前发现的: 当您在例如添加圆圈标记。当您的数据集为空(0 行)时,这必然会发生。

    我设法通过使用 paste0(...,'') 强制进行类型转换来解决此问题。

    在你的情况下是:

    p <- final %>%
      leaflet() %>% 
      addProviderTiles('CartoDB') %>%
      addCircleMarkers(data = final, 
                       color = ~pal(ZIP.SCORE),
                       label = ~paste0(GEONAME, ''))) 
    

    可能有更优雅的方法可以做到这一点,但至少它对我有用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-03-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-21
      • 2013-08-04
      • 1970-01-01
      • 2014-05-19
      相关资源
      最近更新 更多