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



我正在尝试更新一个功能齐全的r Shiny应用程序,该应用程序允许用户从地图中选择位置以绘制结果(用户以前必须从长时间选择位置名称列表(。我正在遵循这个有用的例子,https://uasnap.shinyapps.io/ex_leaflet/。

一切在本地运作良好,但是当我将其发布到Shinyapps.io,https://jvadams.shinyapps.io/streamshot/时。如果我右键单击窗口(我使用的是Chrome版本58.0.3029.110(,我会收到消息Disconnected from the server. Reload.,然后选择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/. 有关如何解决此问题的任何建议?

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

我在线搜索了一些搜索。我发现了将selectInput中的selectize参数更改为FALSE的建议(默认设置为TRUE(,但这无法解决。我找到了其他一些帖子,但对我来说没有任何意义...关于Ajax和Jquery的事情。

我准备了一个简化的示例应用程序来重现此处发布的问题,但是简化的应用程序毫无问题地工作,https://jvadams.shinyapps.io/testing/。我猜这并不奇怪,因为我正在使用的示例也发布在Shinyapps.io上,而且似乎很好。

真实事物和简化示例有什么区别?真实的东西还有3个数据帧,每个数据框架都有更多记录(最多的行〜30,000(,使用tabsetPanel()tabPanel()的每个选项卡页面有更多图(每个选项卡页面10-15个地块(,并且有一些数据表,也。真实的东西也有一些plotly图。但是真实事物中的所有这些图和表都取决于地图或列表的单个位置选择,就像在简单的示例中一样。

我的连接速度可能是问题吗?我将手机的4G热点用于互联网连接(根据https://fast.com/11 mbps(。

我正在使用R版本3.4.0(2017-04-21(,RSTUDIO版本1.0.143,在带有Intel(R(Core(TM(I7-4600M CPU的PC上,CPU,2.90 GHz处理器,16.0 GB RAM和Microsoft Windows 7 Enterprise操作系统2009服务包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中都可以使用。

相关内容

最新更新