我想知道,我们如何在闪亮的 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)
Run Code Online (Sandbox Code Playgroud)
为了更改地图的大小,我可以更改 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)
Run Code Online (Sandbox Code Playgroud)
我只想知道,如何使地图的大小动态化,以便我可以控制它。任何帮助是极大的赞赏。
您需要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))
}
)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7007 次 |
| 最近记录: |