'Click tolerance in a Shiny/leaflet/tmap R web application

I have a working Shiny/leaflet/tmap web application showing lines the user can click on to plot and display some statistics. However, I find the "click" very sensitive and one has to be extremely precise to select the line. Is there a way to increase the tolerance of the click around the lines?

Here is an extract of the code I use with the relevant parts (I would like to increase the click tolerance on tm_shape(channels_shp):

library(shiny)
library(raster)
library(tmap)

ui <- fillPage(
  tags$head(
    tags$style(HTML("
    .leaflet-clickable {
      cursor: crosshair !important;
    }
    .leaflet-container {
      cursor: default !important;
    }"
    ))
  ),
  
  fillRow(
    flex = c(4, 8),
    ...,
    tmapOutput("map")
  ),
  ...
)

shinyServer(function(input, output, session) {

  water_bodies_shp <- readRDS("./water_bodies.rds")
  channels_shp <- readRDS("./rivers.rds")
  output$map <- renderTmap({
      tm_shape(water_bodies_shp) + tm_fill(col="#4287f5", popup.vars=FALSE) +
      tm_shape(channels_shp) + tm_lines(col="#4287f5", popup.vars=FALSE)
  })

  observe({
    feature <- input$map_shape_click
    if (!is.null(feature$id)){
      tryCatch(
        expr = {
           ...
        },
        error = function(e){
          print(e)
        }
      )
    } 
  })
})


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source