2017-09-24 49 views
0

我的应用程序在本地运行良好。我可以与它进行交互等。但是,在全局部署时,它会立即引发“从服务器断开连接”错误。我一直在Google上搜索几天,并尝试了一切我知道如何尝试。闪亮的应用程序在本地加载,部署时从服务器断开连接

首先第一件事情:

  • 我试图卸载然后再重新安装一堆包
  • 我所有的软件包更新我使用
  • 没有信息都在闪亮的日志。 “这个应用程序目前没有日志。”
  • 我的数据(CSV)只有17MB(3列,1M十岁上下行)
  • 当我把它缩小到只有大约200行我继续有同样的问题
  • 我通过设置去,改变了启动超时时间设置为300,并逐一系统地更改每个其他设置。
  • 我已经阅读了浏览器的JavaScript日志的端到端。他们没有多少意义(可能是因为我不懂JavaScript),但没有任何明显的突出。
  • 我不跟整个文件路径加载我的数据,刚刚结束部分

我的“部署”登录RStudio表示成功部署:

Preparing to deploy application...DONE 
Uploading bundle for application: 193997...DONE 
Deploying bundle: 994423 for application: 193997 ... 
Waiting for task: 489405538 
    building: Building image: 992534 
    building: Fetching packages 
    building: Installing packages 
    building: Installing files 
    building: Pushing image: 992534 
    deploying: Starting instances 
    rollforward: Activating new instances 
    terminating: Stopping old instances 
Application successfully deployed to https://jesstme.shinyapps.io/shinynames/ 
Deployment completed: https://jesstme.shinyapps.io/shinynames/ 

链接到应用程序本身: https://jesstme.shinyapps.io/shinynames/

Server代码:

#set wd & environment---- 
setwd("/Users/OldJess/Dropbox/R Stuff (Home)/ShinyNames") 

#load packages------ 
library(datasets) 
library(ggplot2) 
library(viridis) 
library(ggthemes) 
library(gridExtra) 
library(dplyr) 
library(rdrop2) 
library(shiny) 
library(devtools) 

#base <- read.csv("data/NationalNamesBrief.csv", stringsAsFactors = FALSE,  row.names = NULL, na.strings = c("NA","","#MULTIVALUE")) 

#temporary df for demonstration purposes 
base <- structure(list(Name = c("Ellie", "Ellie", "Ellie", "Ellie", "Ellie", 
          "Ellie"), 
        Year = c(1880L, 1881L, 1882L, 1883L, 1883L, 1884L), 
        Gender = c("F", "F", "F", "F", "M", "F"), 
        Count = c(17L, 27L, 37L, 24L, 7L, 28L)), 
       .Names = c("Name", "Year", "Gender", "Count"), 
       row.names = c(NA, 6L), class = "data.frame") 

#clean data---- 
base$name <- tolower(base$Name) 
base$MF <- as.factor(base$Gender) 

#add ranking data by Year 
base <- base %>% 
    group_by(Year) %>% 
    arrange(Year, desc(Count)) %>% 
    mutate(Rank = row_number()) 

#add ranking data by Year AND Gender 
base <- base %>% 
    group_by(Year, Gender) %>% 
    arrange(Year, desc(Count)) %>% 
    mutate(GenderRank = row_number()) 

#create functions---- 
#function to create line & heat charts 
lineHeatCharts <- function(pickaname){ 
    pickanameLower <- tolower(pickaname) 
    subDf <- subset(base[base$name == pickanameLower,]) 
    heat <- ggplot(subDf, aes(x = Year, y = MF, fill = Count)) + 
    scale_fill_viridis(name = "", 
        option = "B", 
        limits = c(0, max(subDf$Count))) + 
    geom_tile(color = "white", size = 0) + 
    theme_tufte() + 
    theme(axis.text.x = element_text(angle = 90, vjust = 1, hjust = 1), 
     axis.ticks.x = element_blank()) + 
    scale_x_continuous(breaks = seq(min(subDf$Year), 
           max(subDf$Year), by = 5)) + 
    labs(x = "Year", y = "") 
    line <- ggplot(subDf, aes(x = Year, y = Count, fill = MF)) + 
geom_line(aes(colour = factor(subDf$Gender)), size = 1.5) + 
theme_tufte() + 
theme(axis.text.x = element_blank(), 
     axis.ticks.x = element_blank()) + 
scale_x_continuous(breaks = seq(min(subDf$Year), 
           max(subDf$Year), by = 5)) + 
labs(x = "", y = "", color = "") 
    return(grid.arrange(line, heat, 
        ncol = 1, nrow = 2, 
        heights = c(5, 2), top = max(subDf$Name))) 
} 

# Define server logic 
function(input, output) { 

    output$view <- renderPlot({ 
    lineHeatCharts(input$list) 
    }) 
} 

UI代码:

library(shiny) 
library(shinythemes) 

# Define UI for dataset viewer application 
fluidPage(theme = shinytheme("flatly"), 

    # Application title 
    titlePanel("First Names on U.S. Social Security Applications, 1880 - 2014"), 

    sidebarLayout(
    sidebarPanel(
     textInput(inputId = "list", label = "Enter a name:", value = "Ellie"), 

     helpText("Note: This page will take about 30 seconds to load the first  time you open it. Data are from US Social Security applications via data.gov. For privacy, only names with at least 5 babies per year are included. Errors in Social Security form submission, like incorrect sex, are not corrected. Names with special characters and spaces are not included."), 

    submitButton("Refresh View") 
), 

mainPanel(
    h4(""), 
    plotOutput("view") 
    ) 
) 
) 
+1

你能提供整个应用程序吗? –

+0

@PorkChop完成。 – jesstme

回答

0

事实证明有两个问题: 1)我需要删除我的代码setwd()二号线2)闪亮的日志不起作用。

我发布在Google的Shiny论坛上,一个RStudio人员解决了这个问题。一旦日志正常工作,我看到这个错误指向了我试图网络化的东西。删除了该问题并解决了问题。保持这个问题是因为我确信这个问题会在某些时候困扰别人。

1

试试这个:

#set wd & environment---- 
#setwd("/Users/OldJess/Dropbox/R Stuff (Home)/ShinyNames") 

#load packages------ 
library(datasets) 
library(ggplot2) 
library(viridis) 
library(ggthemes) 
library(gridExtra) 
library(dplyr) 
library(shiny) 
library(shinythemes) 

#base <- read.csv("data/NationalNamesBrief.csv", stringsAsFactors = FALSE,  row.names = NULL, na.strings = c("NA","","#MULTIVALUE")) 

#temporary df for demonstration purposes 
base <- structure(list(Name = c("Ellie", "Ellie", "Ellie", "Ellie", "Ellie", "Ellie"), 
         Year = c(1880L, 1881L, 1882L, 1883L, 1883L, 1884L), 
         Gender = c("F", "F", "F", "F", "M", "F"), 
         Count = c(17L, 27L, 37L, 24L, 7L, 28L)), 
        .Names = c("Name", "Year", "Gender", "Count"), 
        row.names = c(NA, 6L), class = "data.frame") 

#clean data---- 
base$name <- tolower(base$Name) 
base$MF <- as.factor(base$Gender) 

#add ranking data by Year 
base <- base %>% 
    group_by(Year) %>% 
    arrange(Year, desc(Count)) %>% 
    mutate(Rank = row_number()) 

#add ranking data by Year AND Gender 
base <- base %>% 
    group_by(Year, Gender) %>% 
    arrange(Year, desc(Count)) %>% 
    mutate(GenderRank = row_number()) 

#create functions---- 
#function to create line & heat charts 
lineHeatCharts <- function(pickaname){ 
    pickanameLower <- tolower(pickaname) 

    if(!any(base$name %in% pickanameLower)){ 
    return() 
    } 

    subDf <- subset(base[base$name == pickanameLower,]) 
    heat <- ggplot(subDf, aes(x = Year, y = MF, fill = Count)) + 
    scale_fill_viridis(name = "", 
         option = "B", 
         limits = c(0, max(subDf$Count))) + 
    geom_tile(color = "white", size = 0) + 
    theme_tufte() + 
    theme(axis.text.x = element_text(angle = 90, vjust = 1, hjust = 1), 
      axis.ticks.x = element_blank()) + 
    scale_x_continuous(breaks = seq(min(subDf$Year), max(subDf$Year), by = 5)) + 
    labs(x = "Year", y = "") 
    line <- ggplot(subDf, aes(x = Year, y = Count, fill = MF)) + 
    geom_line(aes(colour = factor(subDf$Gender)), size = 1.5) + 
    theme_tufte() + 
    theme(axis.text.x = element_blank(), 
      axis.ticks.x = element_blank()) + 
    scale_x_continuous(breaks = seq(min(subDf$Year), 
            max(subDf$Year), by = 5)) + 
    labs(x = "", y = "", color = "") 
    return(grid.arrange(line, heat, ncol = 1, nrow = 2, heights = c(5, 2), top = max(subDf$Name))) 
} 

ui <- fluidPage(theme = shinytheme("flatly"), 

       # Application title 
       titlePanel("First Names on U.S. Social Security Applications, 1880 - 2014"), 

       sidebarLayout(
        sidebarPanel(
        textInput(inputId = "list", label = "Enter a name:", value = "Ellie"), 

        helpText("Note: This page will take about 30 seconds to load the first  time you open it. Data are from US Social Security applications via data.gov. For privacy, only names with at least 5 babies per year are included. Errors in Social Security form submission, like incorrect sex, are not corrected. Names with special characters and spaces are not included."), 

        submitButton("Refresh View") 
       ), 
        mainPanel(
        h4(""), 
        plotOutput("view") 
       ) 
       ) 
) 

server <- function(input, output, session) { 

    output$view <- renderPlot({ 
    lineHeatCharts(input$list) 
    }) 
} 

shinyApp(ui, server) 

enter image description here

+0

除了最后一行之外,还增加了哪些其他更改? – jesstme

+0

我加了'if(!any(base $ name%in%pickanameLower)){return()}' –

相关问题