2

I would like to display flow lines (OD-lines) using leaflet in Shiny and sofar I can successfully map all the lines I want. But I also want to change the line width so that each line will have a different linewidth depending on the attribute they have. I am trying to get the values for weight with the following code but it does not work:

  values <- reactive({
    test[quel==input$zelle&hr==input$std&vmitt==input$vmitt&tag==input$tag]
  })

  observe({
    anzhl <-isolate(values()[,10])
    print(anzhl[1]*2)
    str(anzhl)

    leafletProxy("zones", data = values()) %>% 
    removeShape(layerId="liID") %>% 
    addPolylines(lng=~x_coor, lat=~y_coor, stroke=TRUE, layerId="liID", color="black", weight=sum(anzhl())/100)})

I get the following error message:

Warning: Error in observerFunc: could not find function "anzhl"
Stack trace (innermost first):
    56: observerFunc [E:\.../server.R#118]
     1: runApp
ERROR: [on_request_read] connection reset by peer

What am I doing wrong and is it ever possible to change the line widths with the values called within an interactive session.

1 Answer 1

3

Read the error:

 Warning: Error in observerFunc: could not find function "anzhl"

then look at where your code mentions anzhl:

weight=sum(anzhl())/100)

You have () there, which makes R think it needs to call a function. anzhl is not a function, its a vector or some other data thing. If you want the sum of all the values just do sum(anzhl).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.