闪亮/传单地图未呈现 [英] Shiny/Leaflet map not rendering

查看:76
本文介绍了闪亮/传单地图未呈现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尽管代码本身可以在Shiny之外运行,但我无法在其闪亮的应用程序中呈现传单地图.我没有收到任何错误,所以我被困住了,感谢您的帮助.

样本数据:

cleanbuffalo <- data.frame(name = c("queen","toni","pepper"), 
                           longitude = c(31.8,32,33), 
                           latitude = c(-24,-25,-26))

闪亮的用户界面:

vars <- c(
  "Pepper" = "pepper",
  "Queen" = "queen",
  "Toni" = "toni"
)

shinyUI(navbarPage("Buffalo Migration", id ="nav",

  tabPanel("Interactive Map",

div(class="outer",

    leafletOutput("map", width = "100%", height = "100%"),
    #Panel Selection
    absolutePanel(id = "controls", class = "panel panel-default", fixed = TRUE,
      draggable = TRUE, top = 60, left = "auto", right = 20, bottom = "auto",
      width = 330, height = "auto",

      h2("Buffalo Migration"),
      #Buffalo Group selection
      checkboxGroupInput(
        "checkGroup", label = h3("Select Buffalo to Follow"),
        choices = vars,
        selected = 1)
          )
        )
      )
  )
)

发光的服务器:

library(shiny)
library(dplyr)
library(leaflet)
library(scales)
library(lattice)

shinyServer(function(input, output, session) {
  output$map <- renderLeaflet({
    leaflet() %>% addTiles() %>% setView(lng = 31.88, lat = -25.02, zoom=1)
  })

解决方案

由于leafletOutput中的height参数,它不起作用.奇怪的是,如果您在%中指定地图,则不会显示该地图,但是如果您使用"px"(或将被强制转换为字符串并附加"px"的数字),则可以正常工作.

leafletOutput("map", width = "75%", height = "500px")产生:

我不知道为什么会发生这种情况,但是如果您想在%中指定leafletOutput的高度,则可以将其包装到div中并为其指定适当的高度.


默认情况下,宽度设置为100%,高度设置为400px.因此,您不必指定这些参数-仅当我想更改输出的大小时,才需要这样做.

leafletOutput(outputId, width = "100%", height = 400)

I can't get a leaflet map to render in my shiny app, although the code works by itself outside of shiny. I do not get any errors so I am stuck, any help is appreciated.

Sample Data:

cleanbuffalo <- data.frame(name = c("queen","toni","pepper"), 
                           longitude = c(31.8,32,33), 
                           latitude = c(-24,-25,-26))

Shiny UI:

vars <- c(
  "Pepper" = "pepper",
  "Queen" = "queen",
  "Toni" = "toni"
)

shinyUI(navbarPage("Buffalo Migration", id ="nav",

  tabPanel("Interactive Map",

div(class="outer",

    leafletOutput("map", width = "100%", height = "100%"),
    #Panel Selection
    absolutePanel(id = "controls", class = "panel panel-default", fixed = TRUE,
      draggable = TRUE, top = 60, left = "auto", right = 20, bottom = "auto",
      width = 330, height = "auto",

      h2("Buffalo Migration"),
      #Buffalo Group selection
      checkboxGroupInput(
        "checkGroup", label = h3("Select Buffalo to Follow"),
        choices = vars,
        selected = 1)
          )
        )
      )
  )
)

Shiny Server:

library(shiny)
library(dplyr)
library(leaflet)
library(scales)
library(lattice)

shinyServer(function(input, output, session) {
  output$map <- renderLeaflet({
    leaflet() %>% addTiles() %>% setView(lng = 31.88, lat = -25.02, zoom=1)
  })

解决方案

It doesn't work because of the height parameter in leafletOutput. Strangely, if you specify it in % the map doesn't show up, but if you use "px" (or a number which will be coerced to a string and have "px" appended) it does work fine.

leafletOutput("map", width = "75%", height = "500px") yields:

I don't know why this happens but if you wanted to specify the height of the leafletOutput in % you could wrap it into a div and give it the appropriate height.


By default the width is set to 100% and the height to 400px. So, you don't have to specify these parameters - I would do it only if I wanted to change the size of the output.

leafletOutput(outputId, width = "100%", height = 400)

这篇关于闪亮/传单地图未呈现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆