Setting the position of the searchbox in Leaflet using CSS (leaflet.extra package)

Is it possible to customize the position of the searchbox in Leaflet using CSS, specifically when using the Leaflet extra package in Shiny? Here's a simple code example:


      library(leaflet)
      library(leaflet.extras)
      library(shiny)

      ui <- fillPage(leafletOutput("mymap"))

      server <- function(input, output, session) {
        output$mymap <- renderLeaflet({
          leaflet() %>%
            addProviderTiles(providers$Esri.WorldStreetMap) %>%
            addSearchOSM()
        })

      }

      shinyApp(ui, server)

How can we manipulate the searchbox position, such as placing it in the top center?

Upon inspecting the browser, the following element is identified:

<a class="search-button" href="#" title="Search using Google Geocoder" style="outline: none;"></a>

I attempted to adjust the position using CSS:


      library(leaflet)                  
      library(leaflet.extras)
      library(shiny)

      ui <- fillPage(
       tags$head(tags$style(
         HTML('leaflet-search-button {margin-top: 100px;}
      '))
         ),
        leafletOutput("mymap")
        )

      server <- function(input, output, session) {
        output$mymap <- renderLeaflet({
          leaflet() %>%
            addProviderTiles(providers$Esri.WorldStreetMap) %>%
            addSearchOSM()
        })

      }

      shinyApp(ui, server)

Answer №1

If you want to customize the margin of your search control in Leaflet, you should use the leaflet-control-search selector and make sure to include the !important rule for overriding default styles.

tags$head(tags$style(
  HTML('.leaflet-control-search {
    margin-top: 100px !important;
  }')
))

https://i.sstatic.net/CdmLV.png

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Moving a mouse from one element to another does not reset its state

Link to code: https://codesandbox.io/s/objective-darwin-w0i5pk?file=/src/App.js Description: There are four gray squares in this example, each with a different shade of gray. The goal is to change the background color of each square when the user hovers o ...

- Determine if a div element is already using the Tooltipster plugin

I have been using the Tooltipster plugin from . Is there a way to check if a HTML element already has Tooltipster initialized? I ask because sometimes I need to update the text of the tooltip. To do this, I have to destroy the Tooltipster, change the tit ...

I am interested in modifying the color of the radio button

Using blue, red, and green colors works perfectly fine for me. However, when I try to use orange or the color code #fb0, a strange black radius appears in the center section. accent-color: red accent-color: #fb0 input[type=radio] { accent ...

str_extract can disregard any optional combination of alphanumeric characters

Currently, I am analyzing street addresses. My programming language of choice is R Thankfully, I am familiar with using REGEX for this task. To clarify the situation, I have prepared four examples of the types of addresses we are working with. While I h ...

Tips on Incorporating CSS in import.io Connect Extract

By utilizing the import.io connector, I successfully extracted a portion of HTML from the source website. The output was returned as "html" type, consisting of a single table of data with styles defined in the body HTML but not fully extracted. Consequentl ...

Can you provide guidance on how to prioritize container div style over CSS class?

Here's the HTML code snippet I'm working with: <html> <head> <style> .text-box { color: red; } </style> </head> <body> <p class=&qu ...

Creating a Set of Buttons in HTML

Need some assistance with grouped buttons. Let's consider a scenario where there are 5 buttons on an HTML page. When the 3rd button is clicked, buttons from 0 to 3 should change color and the function should return 3. Similarly, when the 5th button is ...

It is impossible to change the text color to white

I am working on some JSX code which looks like the following: <div style={Object.assign({}, styles.occupyAllScreen, styles.backgroundContainer)}> <div styles={styles.overimposingText}> <h2 styles={{color: 'white !important& ...

All you need to know about the properties of CSS ul

When I specify .a ul{} .a ul li{} as well as .b ul{} .b ul li{} will the properties of ul in .b be completely isolated from the properties of ul in .a? Or will they have some commonalities? I am looking to ensure that the styles for ul remain entirely ...

Drifting my dropdown menu bar through the digital sea

I'm having trouble with my navigation bar and I need help styling it. I want the navigation bar to have a dropdown menu when the user hovers over the top level of the navigation bar. The issue I am facing is that the second level of the navigation bar ...

Alert: the quantity of items requiring replacement is not evenly divisible by the length of replacements needed

I encountered warnings while executing this code. For instance, when I include tm1<- summary(tmfit)[c(4,8,9)], I am able to obtain the output, but I must run this code individually for every $i$. What is causing this error? Is there an alternative ...

Tips for positioning "THANK YOU" in the center

and this is a snippet of my coding <div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true"> <div class=" ...

What is the process for setting up both an open and closed status for my accordion?

After browsing through multiple threads on accordions, none seem to match my current structure which I believed was effective. In an attempt to learn and build elements from scratch, I created the following accordion with some help from Google and experi ...

Outline of a transparent right trapezoid shape

I'm attempting to create a slanted path line that resembles this particular image. The method I am currently using involves two trapezoid shapes, positioning one on top of the other to blend in with the background, as demonstrated in this jsFiddle ex ...

Steps for adjusting the position of the tooltip arrowWould you like to

My current challenge involves repositioning the Tooltip arrow on my hover box to the left side, as it currently appears at the top of the box. This is the CSS I am using: <style type="text/css"> * { font-family: Arial; } .input { position: ...

Expandable Menu that slides up and down

Here is a link to an Accordion Menu I have created: https://jsfiddle.net/wfr57s57/ This piece of JQuery Code controls the functionality: $(".menu-item").click(function(e) { var allContents = $(".menu-content"); e.preventDefault(); if(allC ...

displaying a bar plot segregated by a different column

I've looked around, but can't seem to find an answer to this question. I want to create a bar plot for a variable called "pet" in my dataset "habitat," which has three categorical categories - "Y," "N," and "Null." The code I have that works is ...

What is the best way to determine the count of distinct values within various columns in R?

I am dealing with a massive dataset consisting of 23,500 rows. Each row contains pairs of events that I need to deduplicate and count. To achieve this, I have to tally the unique events across 30 columns in each row and then generate a new column with th ...

Steps for setting a background image behind radio buttons

I am currently facing a challenge in adding a background image to a div that contains some radio buttons and updating it dynamically with Angular based on the current page. app.controller('thingCtrl', function ($scope, $rootScope, $routeParams ...

What is the best way to utilize R to "unify" a dataset of hyphenated addresses?

I have a data frame with four rows of fictional addresses. Some of the addresses are hyphenated, like "2500-2598 Main St." I want to break down these hyphenated addresses into individual rows, creating new entries for 2500 Main St, 2502 Main St, 2504 Main ...