<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: [R] Leaflet Visual works on Desktop, breaks on Service in Custom Visuals Development Discussion</title>
    <link>https://community.fabric.microsoft.com/t5/Custom-Visuals-Development/R-Leaflet-Visual-works-on-Desktop-breaks-on-Service/m-p/4613116#M12323</link>
    <description>&lt;P&gt;&amp;nbsp;Two thoughts come to mind. One, Leaflet is a JavaScript library and the R package simply allows you to use that library to create maps. So, perhaps there is something about the JavaScript running in Desktop versus the Service that is different?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The other is perhaps there is a difference in the sub-packages:&lt;/P&gt;
&lt;P&gt;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/481944"&gt;@MARKZI&lt;/a&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 17 Mar 2025 15:14:34 GMT</pubDate>
    <dc:creator>Greg_Deckler</dc:creator>
    <dc:date>2025-03-17T15:14:34Z</dc:date>
    <item>
      <title>[R] Leaflet Visual works on Desktop, breaks on Service</title>
      <link>https://community.fabric.microsoft.com/t5/Custom-Visuals-Development/R-Leaflet-Visual-works-on-Desktop-breaks-on-Service/m-p/4613071#M12322</link>
      <description>&lt;P&gt;Hello fellow developers,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i have developed a custom R Visual (leaflet map) in Power BI using R Studio. The visual works just as intended on Desktop Version but once i publish the dashboard to services, it seems to run different code. I'm on directQuery mode so the datasource is the same locally as on service. Yes i have matched the recommended Versions for leaflet (2.2.2) and R (4.3.3) on my local instance. I don't use any more packages or crazy functions, everything is build in R functionality.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I basically have this dataframe:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;df &amp;lt;- data.frame(
  Latitude[,1],
  Longitude[,1],
  Timestamp[,1],
  Layers
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;Lat and Long values + a (field) parameter that allows me to pass certain layers to the visual. These layers (columns) are booleans and if set to True the lat long value will be kept, if it is set to false the lat long value will be dropped.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;#Get only the extra layers (not the lat longs and timestamp):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;extra_columns &amp;lt;- setdiff(colnames(Layers), c("timestamp", "geo_lat", "geo_long")) &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;# If there are NA values they will be dropped:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;df &amp;lt;- df[rowSums(is.na(df) | df == "") == 0, ]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;# For each Layer i need to convert the string "True"/"False" into a boolean True /False&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;for (col in extra_columns) {
  if (col %in% colnames(df)) {
    df[[col]] &amp;lt;- as.logical(ifelse(is.na(df[[col]]), FALSE, df[[col]]))
  }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Now i create one map layer per extra column with the respective True/False Filtering of that column.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;for (col in extra_columns) {
  filtered_data &amp;lt;- df[df[[col]] == TRUE, ]
  
  num_points &amp;lt;- nrow(filtered_data)
  
  if (num_points &amp;gt; 0) {
    layer_color &amp;lt;- generate_random_color()
    
    layer_colors[[col]] &amp;lt;- layer_color
    layer_labels[[col]] &amp;lt;- col
        
    map &amp;lt;- map %&amp;gt;%
      addCircleMarkers(
        lng = filtered_data$Longitude,
        lat = filtered_data$Latitude,
        radius = 5,
        color = layer_color,
        stroke = FALSE,
        fillOpacity = 0.8,
        group = col,
        label = ~paste("colnames: ", colnames(filtered_data)) %&amp;gt;% lapply(htmltools::HTML)
      )
  }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;This works perfectly when locally executed, however once published it seems that there is no filtering and for what reason ever i get all datapoints on every layer. I have no idea why though.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Mar 2025 14:58:51 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Custom-Visuals-Development/R-Leaflet-Visual-works-on-Desktop-breaks-on-Service/m-p/4613071#M12322</guid>
      <dc:creator>MARKZI</dc:creator>
      <dc:date>2025-03-17T14:58:51Z</dc:date>
    </item>
    <item>
      <title>Re: [R] Leaflet Visual works on Desktop, breaks on Service</title>
      <link>https://community.fabric.microsoft.com/t5/Custom-Visuals-Development/R-Leaflet-Visual-works-on-Desktop-breaks-on-Service/m-p/4613116#M12323</link>
      <description>&lt;P&gt;&amp;nbsp;Two thoughts come to mind. One, Leaflet is a JavaScript library and the R package simply allows you to use that library to create maps. So, perhaps there is something about the JavaScript running in Desktop versus the Service that is different?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The other is perhaps there is a difference in the sub-packages:&lt;/P&gt;
&lt;P&gt;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/481944"&gt;@MARKZI&lt;/a&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Mar 2025 15:14:34 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Custom-Visuals-Development/R-Leaflet-Visual-works-on-Desktop-breaks-on-Service/m-p/4613116#M12323</guid>
      <dc:creator>Greg_Deckler</dc:creator>
      <dc:date>2025-03-17T15:14:34Z</dc:date>
    </item>
    <item>
      <title>Re: [R] Leaflet Visual works on Desktop, breaks on Service</title>
      <link>https://community.fabric.microsoft.com/t5/Custom-Visuals-Development/R-Leaflet-Visual-works-on-Desktop-breaks-on-Service/m-p/4615884#M12335</link>
      <description>&lt;P&gt;Coming back to this thread with the solution:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I noticed that the class(df[,4]) with 4 being one of my True/False Layer returned different types on local and on services. On Local i received character which i succesfully casted on logical. On Services this line of code returned integer. I played around with more robust casting and datatype differentiation and fixed it like this:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;for (col in extra_columns) {
  if (col %in% colnames(df)) {
    if (!is.logical(df[[col]])) { 
      df[[col]] &amp;lt;- as.logical(ifelse(df[[col]] %in% c("True", "true", "1"), TRUE, FALSE))
    }
  }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Mar 2025 08:49:47 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Custom-Visuals-Development/R-Leaflet-Visual-works-on-Desktop-breaks-on-Service/m-p/4615884#M12335</guid>
      <dc:creator>MARKZI</dc:creator>
      <dc:date>2025-03-19T08:49:47Z</dc:date>
    </item>
  </channel>
</rss>

