3

我正在尝试在 shinyapp.io 上运行我闪亮的应用程序。

https://mrmoleje.shinyapps.io/north-america-massacres/

该应用程序在 R Studio 中运行良好,但是在服务器中,我的传单地图中的“弹出窗口”完全消失了。shiny.io 日志中没有任何内容可以帮助我,而且我在网上找不到任何指导。以下是该应用程序的代码:

d <- data.frame(massacre_name = c("name1", "name2"),
            date = c(1345, 6754),
            native_casualties=c(0, 0),
            Tribe_name=c("named", "named"),
            latitude=c(30.2, 32.4),
            longitude=c(-84, -87.1),
            web=c("www.address.com", "www.address2.com")
            )

#load libraries----
library(readxl)
library(leaflet)
library(dplyr)
library(htmltools)
library(shiny)
library(shinythemes)

#create the UI
ui <- {fluidPage(theme = shinytheme("slate"), titlePanel("Massacres in 
North America involving 
                                                     First Nations Peoples: 1500-1700"), 
             sidebarLayout(position = "right",
                           sidebarPanel(
                             selectInput(inputId = "input1", label = "Tribe name" ,choices = 
                                           unique(d$Tribe_name))

                           ),

                           mainPanel(
                             leafletOutput("mymap"))
             )
)}


server <- function(input, output) {
 react <- reactive({
req(input$input1)
df <- d[d$Tribe_name == input$input1,]
df
  }) 

 output$mymap <- renderLeaflet({ req(input$input1)

leaflet(data = react()) %>% addTiles() %>% setView(lng = -100.94, lat = 38.94 , zoom = 3.5) %>% 
  addProviderTiles(providers$Esri.NatGeoWorldMap) %>% 
  addMarkers(lng = ~longitude, lat= ~latitude, 
             popup = paste(react()$massacre_name, "<br>", "Date:", 
react()$date, 
                           "<br>", "Number of native casualties:", 
react()$native_casualties,
                           "<b><a href"= react()$web))

  })
}


shinyApp(ui, server)

关于为什么弹出窗口不出现在服务器版本中的任何想法?

4

1 回答 1

2

我认为问题在于您没有为addMarkers. 如果您将该功能更改为addCircleMarkers您的应用程序可以使用,也可以使用弹出窗口。

如果您创建一个图标并将其包含在其中,addMarkers它也应该可以工作。它对我有用。:)

#load libraries----
library(leaflet)
library(dplyr)
library(htmltools)
library(shiny)
library(shinythemes)

d <- data.frame(massacre_name = c("name1", "name2"),
                date = c(1345, 6754),
                native_casualties=c(0, 0),
                Tribe_name=c("named1", "named2"),
                latitude=c(30.2, 32.4),
                longitude=c(-84, -87.1),
                web=c("www.address.com", "www.address2.com"), stringsAsFactors = F
)

#create the UI
ui <- {fluidPage(theme = shinytheme("slate"), titlePanel("Massacres in 
                                                         North America involving 
                                                         First Nations Peoples: 1500-1700"), 
                 sidebarLayout(position = "right",
                               sidebarPanel(
                                 selectInput(inputId = "input1", label = "Tribe name" ,choices = 
                                               unique(d$Tribe_name))

                               ),

                               mainPanel(
                                 leafletOutput("mymap")
                                 )
                 )
)}


server <- function(input, output) {


  react <- reactive({
    req(input$input1)
    df <- d[d$Tribe_name == input$input1,]
    df
  }) 

  greenLeafIcon <- makeIcon(
    iconUrl = "http://leafletjs.com/examples/custom-icons/leaf-green.png",
    iconWidth = 38, iconHeight = 95,
    iconAnchorX = 22, iconAnchorY = 94,
    shadowUrl = "http://leafletjs.com/examples/custom-icons/leaf-shadow.png",
    shadowWidth = 50, shadowHeight = 64,
    shadowAnchorX = 4, shadowAnchorY = 62
  )

  output$mymap <- renderLeaflet({ req(input$input1)

    leaflet(data = react()) %>% addTiles() %>% setView(lng = -100.94, lat = 38.94 , zoom = 3.5) %>% 
      addProviderTiles(providers$Esri.NatGeoWorldMap) %>%
      addMarkers(lng = react()$longitude, lat= react()$latitude, icon=greenLeafIcon, 
                 popup = paste(react()$massacre_name, "<br>", "Date:",
                               react()$date,
                               "<br>", "Number of native casualties:",
                               react()$native_casualties,
                               "<b><a href"= react()$web)
      ) 
  })
}

shinyApp(ui, server)
于 2018-06-24T14:24:41.547 回答