R Shiny文档:条件映射未显示时的间隙

时间:2017-11-09 16:04:32

标签: r shiny leaflet

我正在制作一个闪亮的互动文档。我希望为用户提供以复选框状态为条件显示地图的选项,并且该地图具有一些反应内容。我能够实现这一点,但不能没有地图在不显示时占用的空间。我相信情节而不是地图也是如此。

地图的缺席是否可以留下空隙?

---
title: "Conditional Map"
runtime: shiny
output: html_document
---

```{r setup, include=FALSE, results='hide'}
knitr::opts_chunk$set(echo = FALSE)
library(leaflet)
library(shiny)
```

The map should be present based upon the condition of the checkbox:

```{r}
# coordinates for markers:
Coords = list("London"=c(0,51), "New York" = c(-74,40))

selectInput(inputId = "Loc",label = "Select location", choices = names(Coords))

checkboxInput(inputId = "ShowMap", label="Show map?", value=TRUE)

leafletOutput("Map")

output$Map = renderLeaflet({if(input$ShowMap) leaflet() %>% addTiles %>% 
setView(-45,45,zoom=2) %>%
addMarkers(lng=Coords[[input$Loc]][1],lat=Coords[[input$Loc]][2])})

```

## The Next Bit

Some additional content here which should appear directly below the previous content, whether that is the map or the checkbox.

1 个答案:

答案 0 :(得分:1)

像这样使用条件面板:

conditionalPanel(condition = "input.ShowMap == true", 
leafletOutput("Map"))