gpt4 book ai didi

r 传单 shiny app in shiny.io 错误

转载 作者:行者123 更新时间:2023-12-04 10:34:23 25 4
gpt4 key购买 nike

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

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

该应用程序在 R Studio 中运行良好,但在服务器中,我的传单 map 中的“弹出窗口”完全消失了。 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)

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

最佳答案

我认为问题在于您没有为 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)

关于r 传单 shiny app in shiny.io 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51004750/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com