【问题标题】:Add a logo to a leaflet map in a shiny app在闪亮的应用程序中将徽标添加到传单地图
【发布时间】:2022-01-11 13:19:32
【问题描述】:

我想在闪亮应用中的传单地图中添加徽标。

leafem 包的 addLogo 函数允许这样做,当我在闪亮环境之外生成地图时,该函数可以完美运行,但是在闪亮环境中应用该函数时它不起作用。

我不知道我可以避免什么,或者是否有其他方法可以做到这一点。

├── app.R
└── www
    └── Logo.png
library(leaflet)
library(shiny)
library(leafem)


ui <- fluidPage(
  
  leafletOutput("map")
  
)

server <- function(input, output, session) {
  
  output$map <- renderLeaflet({    
    
    leaflet() %>%
      addTiles() %>%
      setView(lng = -79.442471,
              lat = 43.6857,
              zoom = 12) %>%
      addLogo("Logo.png",
              src= "local")    
    
    
  })
  
  
}

shinyApp(ui, server)



【问题讨论】:

    标签: r shiny leaflet shinyjs


    【解决方案1】:

    addLogo 中使用src= "remote"。即使 Shiny 应用程序和图像在您的本地计算机中,您也需要将其用作 remote。使用 local 将指向 ../graphs/Logo.png 而不仅仅是 Logo.png(这是 www 目录下的文件的默认值)。

    library(leaflet)
    library(shiny)
    library(leafem)
    
    
    ui <- fluidPage(
      
      leafletOutput("map")
      
    )
    
    server <- function(input, output, session) {
      
      output$map <- renderLeaflet({    
        
        leaflet() %>%
          addTiles() %>%
          setView(lng = -79.442471,
                  lat = 43.6857,
                  zoom = 12) %>%
          addLogo("Logo.png",
                  src= "remote")    
      })
      
      
    }
    
    shinyApp(ui, server)
    

    【讨论】:

    • 谢谢!!我不知道我以前怎么没有尝试过......
    猜你喜欢
    • 2015-06-15
    • 2015-06-11
    • 2018-03-13
    • 1970-01-01
    • 2023-01-11
    • 1970-01-01
    • 2020-06-16
    • 1970-01-01
    • 2017-07-27
    相关资源
    最近更新 更多