Error in : $ operator is invalid for atomic vectors

Why this shiny Ui code always error?. Please help me. thank youu.

Code :

tabsetPanel(id="mainPanel",
                            type = "pills"
tabPanel("Haze Trajectory",
                                     hr(),
                                     tabsetPanel(id ='Foo',
                                                 type = "tab",
tabPanel('Initial point from hotspot sequence',
                                                          sidebarLayout(fluid = TRUE,
                                                                        sidebarPanel(h4('HYSPLIT Simulation'),
                                                                                     h5('Initial Point :'),
                                                                                     selectInput('date_Period',
                                                                                                 'Hotspot Sequence',
                                                                                                 choices = c(Choose = '',
                                                                                                            ....),
                                                                                      selectize = TRUE),
                                                                                     actionButton('go_sim', 'Start'),
                                                                                     uiOutput("warnFeb"),
                                                                                     width = 3),
                                                                        
                                                                        mainPanel(fluid = TRUE,
                                                                                  h3(textOutput('caption_traj')),
                                                                                  h5('Description and visualization of haze trajectory simulation'),
                                                                                  leafletOutput('showplotleaflet',
                                                                                                height = 500),
                                                                                  h4(textOutput('titleSimulation3')),
                                                                                  dataTableOutput('simulation_traj')
                                                                                  )
                                                                        )
                                                          )

Error :
Warning: Error in : $ operator is invalid for atomic vectors
98: renderWidget
97: transform
96: func
94: f
93: Reduce
84: do
83: hybrid_chain
82: origRenderFunc
81: output$showplotleaflet
1: runApp

I think it isn't the UI code that is causing the error. If you look at the traceback output, the error is occurring when the server code tries to render the showplotleaflet UI element.

1 Like

It looks like you're trying to use something that isn't a list as though it were a list, with the $ operator. E. g.

foo <- c("some", "text", "in", "vector")
foo$bar
# This returns the error message: 'Error in foo$bar : $ operator is invalid for atomic vectors'

Something similar seems to be happening in your script. You could try using ctrl+F(Cmd+F on a Mac) to search through the script for instances of $ and see where you've used the operator. It should be easy to fix once you find it :slight_smile:

thank you sir, I'll try to trace it first

thank you, I'll try to trace it first

Show us this block:

output$showplotleaflet <- ???

this my code :

 output$showplotleaflet <- renderLeaflet({
    input$go_sim
    if (input$go_sim == 0)
      return("Please click 'Start  Simulation' button to see the result")
    # else
    #   #PROGRESS BAR
    progress <- shiny::Progress$new(session, min = 1, max = 10)
    on.exit(progress$close())
    progress$set(message = 'Plotting in progress')
    
    for (i in 1:10) {
      progress$set(value = i)
      Sys.sleep(0.5)
      disable("go_sim")
    }
    enable("go_sim")
    isolate(plot_leaflet_traj())
  })
 plot_leaflet_traj <- reactive({
    dataplot <- tabel_traj()$hasil_sim_traj
    dataplot$color <- as.character(dataplot$receptor)
    dataplot$color[dataplot$color == "1"] <- "#F44336" #"red"
    dataplot$color[dataplot$color == "2"] <- "#4CAF50" #green
    dataplot$color[dataplot$color == "3"] <- "aqua"
    dataplot$color[dataplot$color == "4"] <- "#2196F3" #blue
    dataplot$color[dataplot$color == "5"] <- "#FF9800" #orange
    dataplot$color[dataplot$color == "6"] <- "#FFEB3B" #yellow
    dataplot$color[dataplot$color == "7"] <- "#673AB7" #deep purple
    dataplot$color[dataplot$color == "8"] <- "#f1c40f" #sunflower
    dataplot$color[dataplot$color == "9"] <- "#795548" #brown
    dataplot$color[dataplot$color == "10"] <- "#8BC34A" #light green
    dataplot$color[dataplot$color == "11"] <- "#BA68C8" #purple
    dataplot$color[dataplot$color == "12"] <- "#607D8B" #blue grey
    dataplot$color[dataplot$color == "13"] <- "#009688" #teal
    dataplot$color[dataplot$color == "14"] <- "#E91E63" #pink
    dataplot$color[dataplot$color == "15"] <- "#3F51B5" #indigo
    dataplot$color[dataplot$color == "16"] <- "#CDDC39" #lime
    dataplot$color[dataplot$color == "17"] <- "#FFC107" #amber
    dataplot$color[dataplot$color == "18"] <- "#FF5722" #deeporange
    dataplot$color[dataplot$color == "19"] <- "#c0392b" #pomegranade
    dataplot$color[dataplot$color == "20"] <- "#3498db" #peterriver
    dataplot$color[dataplot$color == "21"] <- "#e74c3c" #alizarin
    dataplot$color[dataplot$color == "22"] <- "#2980b9" #belizehole
    dataplot$color[dataplot$color == "23"] <- "#16a085" #greensea
    dataplot$color[dataplot$color == "24"] <- "#2c3e50" #midnightblue
    dataplot$color[dataplot$color == "25"] <- "#95a5a6" #concreate
    dataplot$color[dataplot$color == "26"] <- "#69F0AE" #greenA200
    dataplot$color[dataplot$color == "27"] <- "#76FF03" #lightgreenA400
    dataplot$color[dataplot$color == "28"] <- "#827717" #lime900
    dataplot$color[dataplot$color == "29"] <- "#FFFF00" #yellowA200
    dataplot$color[dataplot$color == "30"] <- "#3E2723" #brown900
    dataplot$color[dataplot$color == "31"] <- "#FF6E40" #deeporangeA200
    dataplot$color[dataplot$color == "32"] <- "#FF9E80" #deeporangeA100
    dataplot$color[dataplot$color == "33"] <- "#FF1744" #redA400
    dataplot$color[dataplot$color == "34"] <- "#D50000" #redA700
    dataplot$color[dataplot$color == "35"] <- "#D500F9" #purpleA400
    dataplot$color[dataplot$color == "36"] <- "#E57373" #red300
    dataplot$color[dataplot$color == "37"] <- "#F06292" #pink300
    
    basedreceptor <- (paste("Receptor : ", dataplot$receptor, "<br/>"))
    longitudepaste <- (paste("Longitude : ", dataplot$lon, "<br/>"))
    latitudepaste <- (paste("Latitude : ", dataplot$lat, "<br/>"))
    heightpaste <- (paste("Height: ", dataplot$height, "<br/>"))
    pressurepaste <- (paste("Pressure : ", dataplot$pressure, "<br/>"))
    datepaste <- (paste("Date : ", dataplot$traj_dt, "<br/>"))
    CO2paste <- (paste("CO2(kg/m2s) : ", dataplot$co2, "<br/>"))
    COpaste <- (paste("CO(kg/m2s) : ", dataplot$co, "<br/>"))
    popup1 <- (paste(basedreceptor,longitudepaste, latitudepaste, heightpaste, pressurepaste, datepaste, CO2paste, COpaste, sep = ""))
    
    mymap = leaflet()
    
    mymap <-
      addProviderTiles(
        mymap,
        "OpenStreetMap",
        group = "OpenStreetMap")
    mymap <-
      addProviderTiles(
        mymap,
        "CartoDB.DarkMatter",
        group = "CartoDB Dark Matter")
    mymap <-
      addProviderTiles(
        mymap,
        "CartoDB.Positron",
        group = "CartoDB Positron")
    mymap <-
      addProviderTiles(
        mymap,
        "Esri.WorldTerrain",
        group = "ESRI World Terrain")
    mymap <-
      addProviderTiles(
        mymap,
        "Stamen.Toner",
        group = "Stamen Toner")
    mymap <-
      addLayersControl(
        mymap,
        position = "topright",
        baseGroups = c("CartoDB Positron",
                       "CartoDB Dark Matter",
                       "Stamen Toner",
                       "ESRI World Terrain"))
    
    
    mymap=addCircleMarkers(mymap, lng = dataplot$lon, lat = dataplot$lat, color = dataplot$color, fillOpacity = 1, stroke = FALSE, weight = 7, fill = TRUE, opacity = 1, radius = 3, popup = popup1)
    mymap = addLegend(mymap, "bottomright", 
                      #legend=as.character(unique(dataplot$receptor)),
                      colors = unique(dataplot$color),
                      labels= as.character(unique(dataplot$receptor)),
                      title= "Receptor",
                      opacity = 1)
    leafIcons <- list(iconUrl = "http://findicons.com/files/icons/2203/alcohol/32/burn.png", iconSize = c(18, 18))
    point_indicator<-subset(dataplot,dataplot$hour_along==0)
    mymap = addMarkers(mymap, lng = point_indicator$lon, lat = point_indicator$lat, icon = leafIcons)
    mymap = addScaleBar(mymap, position = c("bottomleft"), options = scaleBarOptions())
    html_legend <- "<img src='https://findicons.com/files/icons/767/wp_woothemes_ultimate/96/compass.png'>"
    mymap <- addControl(mymap,html = html_legend, position = "topright")
    html_legend2 <- "<img src='http://findicons.com/files/icons/2203/alcohol/32/burn.png'>hotspot"
    mymap <- addControl(mymap,html = html_legend2, position = "bottomleft")
  })

So tabel_traj() is a list with an element called hasil_sim_traj which is a ?dataframe?

You use this to build mymap which is a leaflet.

Normally you would put mymap on a line by itself at the end of plot_leaflet_traj to make it clear that you are returning mymap as plot_leaflet_traj().

You have isolated plot_leaflet_traj() in output$showplotleaflet, won't this prevent plot_leaflet_traj() being refreshed in response to output$showplotleaflet? If you have not used plot_leaflet_traj() elsewhere it might not be initialised?

yes, hasil_sim_traj is dataframe and I have initiated plot_leaflet_traj. Which part of the code should I change sir?

Don't know. Post a reprex.