2017-11-09 3 views
0

Ich erstelle ein Shiny interaktives Dokument. Ich möchte dem Benutzer die Möglichkeit geben, eine Karte abhängig vom Checkbox-Status anzuzeigen, und diese Map hat reaktiven Inhalt. Ich kann das erreichen, aber nicht ohne den Platz, den die Karte einnimmt, wenn sie nicht angezeigt wird. Ich glaube, das gilt auch für eine Handlung anstelle einer Karte.R Glänzendes Dokument: Lücke, wenn die bedingte Karte nicht angezeigt wird

Ist es möglich, dass die Abwesenheit der Karte keine Lücke lässt?

--- 
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. 

Antwort

1

Verwenden bedingte Panel wie folgt:

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