gpt4 book ai didi

R Shiny 应用程序 - "Disconnected from the server. Reload."

转载 作者:行者123 更新时间:2023-12-04 03:11:45 25 4
gpt4 key购买 nike

我正在尝试更新功能齐全的 R Shiny 应用程序,该应用程序具有允许用户从 map 中选择位置以绘制结果的功能(用户以前必须从一长串名称中选择位置)。我正在关注这个有用的例子,https://uasnap.shinyapps.io/ex_leaflet/ .

一切都在本地运行良好,但当我将其发布到 shinyapps.io 时却不行,https://jvadams.shinyapps.io/StreamShot/ .我收到消息 Disconnected from the server. Reload.如果我右键单击窗口(我使用的是 Chrome 版本 58.0.3029.110)并选择 Inspect并查看控制台选项卡,我看到警告消息 [Deprecation] Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check https://xhr.spec.whatwg.org/. 关于如何解决这个问题有什么建议吗?

我得到相同的 Disconnected from the server. Reload.当我尝试在 Internet Explorer(版本 11.0.9600.18697)中打开应用程序时出现消息。但是,当我右键单击时,Inspect ,然后查看那里的控制台选项卡,我没有错误或警告。

我在网上做了一点搜索。我找到了更改 selectize 的建议selectInput 中的参数至 FALSE (默认设置为 TRUE),但这并没有解决问题。我找到了其他一些帖子,但它们对我来说没有意义……关于 ajax 和 jquery 的事情我不明白。

我准备了一个非常简化的示例应用程序来重现问题以在此处发布,但简化的应用程序没有任何问题,https://jvadams.shinyapps.io/Testing/ .我想这并不奇怪,因为我正在使用的示例也发布在 shinyapps.io 上并且它似乎工作正常。

真实的东西和简化的例子有什么区别?真实的东西有 3 个数据框,每个数据框有更多的记录(最大行数 ~ 30,000),有更多的图(每个标签页 10-15 个图,使用 tabsetPanel()tabPanel() ),并且有还有一些数据表。实物也有几个plotly地 block 。但是,真实情况中的所有这些图和表都依赖于从 map 或列表中做出的单一位置选择,就像在简单示例中一样。

我的连接速度可能有问题吗?我使用手机的 4G 热点连接互联网(根据 https://fast.com/ 为 31 Mbps)。

我在配备 Intel(R) Core(TM) i7-4600m CPU、2.90 GHz 处理器、16.0 GB RAM 的 PC 上使用 R 版本 3.4.0 (2017-04-21)、RStudio 版本 1.0.143和 Microsoft Windows 7 Enterprise 操作系统 2009 Service Pack 1。

下面完整显示了简单示例的 Rmarkdown (*.Rmd) 代码:

---
output: html_document
runtime: shiny
---

```{r setup, include=FALSE, echo=FALSE}
knitr::opts_chunk$set(warning=FALSE, message=FALSE, echo=FALSE)
```

```{r}
# non reactive stuff
library(leaflet)
library(rbokeh)
library(tidyverse)

locs <- structure(list(loc = c("S-US-611: BAD RIVER", "H-US-216: TROUT RIVER",
"M-US-67: GIERKE CREEK", "H-US-71: TROUT CREEK", "S-US-13: PENDILLS CREEK",
"O-US-67: RICE CR.", "M-US-271: EPHRAIM CREEK", "M-US-674: GIBSON CREEK (HALFWAY CREEK)",
"S-US-64: SUCKER RIVER", "M-US-339: EAST TWIN RIVER"), lon = c(-90.652399,
-83.826602, -86.336641, -84.103548, -84.819236, -76.56845, -87.179319,
-86.206658, -85.942378, -87.563722), lat = c(46.637999, 45.428862,
45.849507, 45.979098, 46.443969, 43.443795, 45.148478, 42.719827,
46.674155, 44.151644), le = c(1.10611, 3.10216, 2.10067, 3.10071,
1.10013, 5.10067, 2.10271, 2.10674, 1.10064, 2.10339)), .Names = c("loc",
"lon", "lat", "le"), row.names = c(NA, -10L), class = "data.frame")
row.names(locs) <- locs$loc

chem <- structure(list(le = c(1.00093, 1.00093, 1.00093, 1.00093, 1.00093,
1.00093, 1.00093, 1.00093, 1.00093, 1.00116, 1.00116, 1.00116,
1.00116, 1.00116, 1.00301, 1.00301, 1.00301, 1.00301, 1.00301,
1.00301, 1.00301, 1.00374, 1.00374, 1.00374, 1.00374, 1.00374,
1.00374, 1.00374, 1.00374, 1.00374, 1.00374, 1.00374, 1.00374,
1.00374, 1.10013, 1.10013, 1.10013, 1.10013, 1.10013, 1.10013,
1.10015, 1.10064, 1.10064, 1.10064, 1.10064, 1.10064, 1.10064,
1.10064, 1.10064, 1.10064, 1.10064, 1.10064, 1.10064, 1.10064,
1.10064, 1.10064, 1.10064, 1.10064, 1.10064, 1.10064, 1.10064,
1.10064, 1.10064, 1.10064, 1.10064, 1.10064, 1.10064, 1.10064,
1.10064, 1.10064, 1.10064, 1.10064, 1.10611, 1.10611, 1.10611,
1.10611, 1.10611, 1.10611, 1.10611, 1.10611, 1.10611, 1.10611,
1.10611, 1.10611, 1.10611, 1.10611, 1.10611, 1.10611, 1.10611,
1.10611, 1.10611, 1.10611, 1.10611, 2.10271, 2.10339, 2.10339,
2.10339, 2.10339, 2.10339, 2.10339, 2.10339, 2.10339, 2.10523,
2.10523, 2.10523, 2.10523, 2.10523, 2.10523, 2.10523, 2.10523,
2.10523, 2.10523, 2.10523, 2.10523, 2.10523, 2.10674, 2.10674,
3.10071, 3.10071, 3.10071, 3.10071, 3.10071, 3.10071, 3.10071,
3.10071, 3.10071, 3.10071, 3.10071, 3.10071, 3.10202, 3.10202,
3.10202, 3.10202, 3.10202, 3.10202, 3.10202, 3.10202, 3.10202,
3.10202, 3.10202, 3.10202, 3.10202, 3.10202, 3.10202, 3.10202,
3.10202, 3.10202, 3.10202, 3.10202, 3.10202, 3.10216, 3.10216,
3.10216, 3.10216, 3.10216, 3.10216, 3.10216, 3.10216, 3.10216,
3.10216, 3.10216, 3.10216, 3.10216, 3.10216, 3.10216, 3.10296,
3.10296, 3.10296, 3.10296, 3.10296, 3.10296, 3.10296, 3.10296,
3.10296, 3.10296, 3.10296, 3.10296, 3.10296, 3.10296, 3.10296,
5.10067, 5.10071, 5.10071, 5.10071, 5.10071, 5.10071, 5.10071,
5.10071, 5.10071, 5.10071, 5.10071), year = c(1962L, 1966L, 1971L,
1975L, 1984L, 1997L, 2001L, 2008L, 2012L, 1991L, 1995L, 1999L,
2004L, 2009L, 1963L, 1966L, 1971L, 1978L, 1988L, 2005L, 2012L,
1963L, 1967L, 1971L, 1975L, 1978L, 1982L, 1986L, 1990L, 1994L,
1999L, 2003L, 2007L, 2009L, 1959L, 1963L, 1973L, 1982L, 1988L,
2012L, 2012L, 1958L, 1959L, 1961L, 1963L, 1965L, 1967L, 1969L,
1971L, 1972L, 1973L, 1974L, 1975L, 1977L, 1979L, 1980L, 1981L,
1982L, 1983L, 1984L, 1985L, 1986L, 1987L, 1989L, 1990L, 1992L,
1994L, 1996L, 1998L, 2002L, 2006L, 2010L, 1960L, 1963L, 1964L,
1968L, 1969L, 1971L, 1973L, 1977L, 1978L, 1980L, 1984L, 1988L,
1991L, 1995L, 1998L, 2001L, 2003L, 2005L, 2007L, 2008L, 2011L,
1963L, 1975L, 1979L, 1982L, 1987L, 1995L, 2000L, 2004L, 2008L,
1963L, 1967L, 1971L, 1974L, 1978L, 1983L, 1987L, 1991L, 1995L,
1999L, 2002L, 2006L, 2010L, 1965L, 1984L, 1966L, 1970L, 1972L,
1973L, 1975L, 1979L, 1984L, 1989L, 1994L, 2001L, 2005L, 2009L,
1968L, 1972L, 1974L, 1976L, 1977L, 1979L, 1980L, 1982L, 1984L,
1985L, 1986L, 1988L, 1991L, 1993L, 1994L, 1997L, 1998L, 2002L,
2008L, 2009L, 2012L, 1967L, 1970L, 1974L, 1978L, 1982L, 1985L,
1989L, 1993L, 1997L, 2000L, 2004L, 2005L, 2006L, 2007L, 2011L,
1969L, 1972L, 1975L, 1979L, 1980L, 1983L, 1985L, 1989L, 1993L,
1997L, 2000L, 2002L, 2006L, 2008L, 2011L, 1972L, 1978L, 1982L,
1985L, 1988L, 1991L, 1995L, 1998L, 2002L, 2005L, 2011L), alk.mgl = c(33,
27, 20, 26, 14, 27, 51, 28, 26, 19, 20, 22, 27, 20, 78, 78, 68,
73, 71, 83, 73, 27, 19, 27, 18, 15, 12, 13, 15, 12, 30, 17, 12,
37, 38, 34, 34, 30, 36, 40, 62, 60, 68, 48, 66, 65, 56, 68, 48,
46, 50, 60, 70, 54, 56, 54, 76, 50, 24, 68, 62, 70, 80, 67, 71,
70, 62, 60, 61, 70, 77, 45, 46, 20, 56, 91, 50, 52, 46, 82, 54,
58, 82, 96, 86, 86, 99, 84, 86, 96, 67, 86, 99, 200, 175, 266,
256, 288, 280, 250, 202, 264, 142, 158, 150, 165, 182, 162, 148,
160, 158, 155, 150, 170, 160, 84, 68, 95, 58, 80, 116, 55, 55,
58, 36, 62, 60, 93, 80, 149, 159, 165, 164, 176, 150, 168, 154,
154, 166, 140, 148, 170, 160, 160, 155, 155, 163, 175, 155, 165,
145, 170, 190, 200, 164, 188, 188, 170, 130, 170, 160, 140, 150,
200, 170, 174, 182, 180, 197, 144, 154, 175, 180, 180, 178, 180,
180, 185, 185, 180, 70, 104, 137, 113, 133, 123, 147, 117, 101,
146, 125)), .Names = c("le", "year", "alk.mgl"), row.names = c(NA,
-191L), class = "data.frame")
```

```{r}
# reactive stuff
theworks <- reactive({
i <- input$location
pick <- locs$loc == i
j <- locs$le[pick]

# map data
infosub <- locs[pick, ]

# chemistry data
CHEMsub <- chem[chem$le==j, ]

list(infosub=infosub, CHEMsub=CHEMsub)
})
```

```{r}
# server
acm_defaults <- function(map, x, y) {
addCircleMarkers(map, x, y, radius=6, color="black",
fillColor="orange", fillOpacity=1, opacity=1, weight=2, stroke=TRUE,
layerId="Selected")
}

# map
output$Map <- renderLeaflet({
leaflet() %>%
# Great Lakes centered
setView(lng=-84, lat=45, zoom=6) %>%
addTiles() %>%
addCircleMarkers(data=locs, radius=6, color="black", label=~loc,
stroke=FALSE, fillOpacity=0.5, group="locations", layerId=~loc)
})

# update the map markers and view on map clicks
observeEvent(input$Map_marker_click, {
p <- input$Map_marker_click
proxy <- leafletProxy("Map")
if(p$id=="Selected"){
proxy %>%
removeMarker(layerId="Selected")
} else {
proxy %>%
setView(lng=p$lng, lat=p$lat, input$Map_zoom) %>%
acm_defaults(p$lng, p$lat)
}
})

# update the location selectInput on map clicks
observeEvent(input$Map_marker_click, {
p <- input$Map_marker_click
if(!is.null(p$id)) {
if(is.null(input$location) || input$location!=p$id) {
updateSelectInput(session, "location", selected=p$id)
}
}
})

# update the map markers and view on location selectInput changes
observeEvent(input$location, {
p <- input$Map_marker_click
p2 <- subset(locs, loc==input$location)
proxy <- leafletProxy("Map")
if(nrow(p2)==0) {
proxy %>%
removeMarker(layerId="Selected")
} else {
if(length(p$id) && input$location!=p$id) {
proxy %>%
setView(lng=p2$lon, lat=p2$lat, input$Map_zoom) %>%
acm_defaults(p2$lon, p2$lat)
} else {
if(!length(p$id)) {
proxy %>%
setView(lng=p2$lon, lat=p2$lat, input$Map_zoom) %>%
acm_defaults(p2$lon, p2$lat)
}
}
}
})

output$alk <- renderRbokeh({
df <- theworks()$CHEMsub
if(dim(df)[1] > 0) {
figure() %>%
ly_points(df$year, df$alk.mgl)
} else {
return()
}
})
```

```{r}
# ui
fluidPage(
fluidRow(
column(4,
h4(strong("Select stream from list or map")),
selectInput("location", "", c("", locs$loc), selected=""),
br(),
h4("Alkalinity"),
rbokehOutput("alk")
),
column(7,
p("(Hover to see identities of other streams.)"),
leafletOutput("Map", width="510px", height="510px")
)
)
)
```

最佳答案

我为真实应用程序加载的库之一来自 Github。当我使用变通方法避免加载该包时,该应用程序在本地和 shinyapps.io 上都能正常工作。

关于R Shiny 应用程序 - "Disconnected from the server. Reload.",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44724070/

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