Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
240 views
in Technique[技术] by (71.8m points)

css - How to make map full-size in R Shiny?

I saw similar issue here on SO (How to get Leaflet for R use 100% of Shiny dashboard height) and this solution worked for me when I used shinydashboard. Now, I changed to bs4Dash library (version 2.0.0 downloaded from GitHub) and this solution doesn't work. Crucial code is here:

bs4Dash::dashboardBody(
  mapboxer::mapboxerOutput("map")
)

and CSS:

#map { 
  height: calc(100vh - 57px) !important;
}

When using this I can see margin(?) on the right side of the map:

enter image description here

I can't remove this margin at all.

When I add vw to CSS:

#map { 
  height: calc(100vh - 57px) !important;
  width: calc(100vw - 73.594px) !important;
}

then this strange margin disappears at all and map is now full size but when I open sidebar on the left and map moves right then scroll bars show up on the right and bottom (which is really annoying):

enter image description here

I tried many CSS combinations to make it work properly but none of them works. All was fine in shinydashboardPlus but in bs4Dash it's not working as before. I also checked this solutions: http://bl.ocks.org/d3noob/7654694 but it's still not a good option.

question from:https://stackoverflow.com/questions/65846266/how-to-make-map-full-size-in-r-shiny

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I've finally found a solution for making mapbox fullsize. I added this chunk of code to CSS:

#map { 
       height: calc(100vh - 57px) !important; 
       width: calc(100vw - 73.594px) !important; 
     }

.wrapper { 
       overflow-x: hidden; 
       overflow-y: auto; 
     }

Thanks to this code, when you open the sidebar no scroll bars appear on the bottom and on the right side and everything works smoothly (ok, text 'Mapbox' and map description on the right-bottom also moves when sidebar is opened but I don't think it's an issue here). I've noticed that those .wrapper style options were default in shinydashboardPlus package but not in bs4Dash so I needed to add them to CSS.

So depending on shiny package and sometimes a map provider there's a need to make some minor changes to CSS code in order to make map fullsize and avoid scroll bars.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...