2016-08-02 43 views
1

我想知道,怎樣才能改變單張地圖的大小,光澤R.例如,考慮下面的代碼:如何在Shiny R中動態改變傳單地圖的大小?

library(leaflet) 
library(shiny) 

app = shinyApp(
    ui = fluidPage(
    sidebarLayout(
     sidebarPanel(sliderInput("obs", 
        "Number of observations:", 
        min = 0, 
        max = 1000, 
        value = 500) 
     ), 
     mainPanel(
     leafletOutput('myMap', width = "200%", height = 1400) 
     ) 
    ) 
), 
    server = function(input, output) { 
    map = leaflet() %>% addTiles() %>% setView(-93.65, 42.0285, zoom = 17) 
    output$myMap = renderLeaflet(map) 
    } 
) 

if (interactive()) print(app) 

對於改變地圖的大小,我可以改變寬度和高度參數UI。當我試圖在服務器上改變它時,它沒有成功。

我不知道,任何可以通過服務器在ui中更改參數的方式。我嘗試了這種方法,但沒有奏效。

library(leaflet) 
library(shiny) 

Height = 1000 
app = shinyApp(
    ui = fluidPage(
    sidebarLayout(
     sidebarPanel(sliderInput("Height", 
        "Height in Pixels:", 
        min = 100, 
        max = 2000, 
        value = 500) 
     ), 
     mainPanel(
     leafletOutput('myMap', width = "200%", height = Height) 
     ) 
    ) 
), 
    server = function(input, output) { 
    Height <- reactive(input$Height) 
    map = leaflet() %>% addTiles() %>% setView(-93.65, 42.0285, zoom = 17) 
    output$myMap = renderLeaflet(map) 
    } 
) 

if (interactive()) print(app) 

我只想知道,如何使地圖的大小動態化,以便我可以控制它。任何幫助是極大的讚賞。

回答

2

你需要渲染leafletOutput在服務器端 像

app = shinyApp(
    ui = fluidPage(
    sidebarLayout(
     sidebarPanel(sliderInput("Height", 
           "Height in Pixels:", 
           min = 100, 
           max = 2000, 
           value = 500) 
    ), 

     mainPanel(
     uiOutput("leaf") 

    ) 
    ) 
), 
    server = function(input, output) { 
    output$leaf=renderUI({ 
     leafletOutput('myMap', width = "200%", height = input$Height) 
    }) 

    output$myMap = renderLeaflet(leaflet() %>% addTiles() %>% setView(-93.65, 42.0285, zoom = 17)) 
    } 
) 
+0

這個工作。謝謝。 –

相關問題