闪亮的帮助:发布和“运行应用程序”将“灰显”,但使用ShinyApp()可以

时间:2019-05-31 21:28:06

标签: r deployment shiny

我正在开发我的第一个Shiny App,在本地运行时看起来很棒,但是如果使用Rstudio“运行App”按钮或通过Shinyapp.io发布时失败。

在通过Shinyapp.io发布时,我确保该目录不是本地目录,并且csv文件位于Applications文件夹中。我已经使用profvis检查了应用程序的性能,并且该应用程序使用352.9 MB内存并且在1060 ms处运行。

这是ui文档:

library(shiny)
library(ggplot2)
library(readr)
library(tidyr)
library(data.table)
library(reshape2)
library(dplyr)
library(DT)
library(shinyWidgets)
library(ggrepel)
library(rsconnect)
library(devtools)


#master document. replaced with github data for sharing
df1 <- read_csv("https://raw.githubusercontent.com/KeithTStory/EnvironmentalAnalytics/master/Shiny/CABIN_explorer/20190522(2)_cabin_habitat_data_mda05_1987-present.csv",
                col_types = cols_only(Site = "c", Day = "i", Year = "i", Status = "c", Type = "c", Variable = "c", Unit = "c", Value  = "n"),
                locale = locale(encoding = "latin1")
                )

attach(df1) #odd that I am having to attach names. Seems to work with names attached though.

#Melt data to give each variable a column for selecting
df2 <- df1 %>%
  mutate(id = row_number()) %>%
  replace(., is.na(.), 0) %>%
  filter(Site != 0, Value > 0) %>%
  spread(key = Variable, value = Value) %>%
  group_by(Year) 

attach(df2)

#remove symbols that are causing issues. Tried to convert encoding but had no success.

colnames(df2) <- gsub(x = colnames(df2), pattern = "[+%-]", replacement = "")
colnames(df2) <- gsub(x = colnames(df2), pattern = " ", replacement = ".")  

df1$Variable <-gsub(x = df1$Variable, pattern = "[+%-]", replacement = "")
df1$Variable <-gsub(x = df1$Variable, pattern = " ", replacement = ".")

#This function is used to in the ui input choices for the y axis
FilterFunc <- function(condition, df) {
  subset.data <- df %>%
    filter(Type == condition)

  data_list <- unique(subset.data$Variable)
  return(as.character(data_list))
}

#useful variables for ui choices

types <- unique(as.factor(df1$Type))
df_sites <- unique(df2$Site)

### ui code_____________________________________________
ui <- fluidPage(

  titlePanel("CABIN Data Explorer (Nelson River)"),

  sidebarPanel(

    selectInput(inputId = "site",
                label = "Select Sampling Site:",
                choices = df_sites,
                selectize = TRUE,
                multiple = TRUE,
                selected = "521"
                ),

    selectInput(inputId = "y",
                label = "Y-axis:",
                choices = list(
                  "Physical Data"      = FilterFunc(types[1], df1), #pulling from df1 since it is pre-spread and simpler to work with
                  "Sediment Chemistry" = FilterFunc(types[2], df1),
                  "Water Chemistry"    = FilterFunc(types[3], df1),   
                  "Channel"            = FilterFunc(types[4], df1), 
                  "Climate"            = FilterFunc(types[5], df1), 
                  "Substrate Data"     = FilterFunc(types[6], df1), 
                  "Hydrology"          = FilterFunc(types[7], df1), 
                  "Topography"         = FilterFunc(types[8], df1), 
                  "Landcover"          = FilterFunc(types[9], df1), 
                  "Bedrock Geology "   = FilterFunc(types[10], df1)
                ),
                selectize = TRUE,
                selected = "Ca"
    )
  ),

  mainPanel(
    plotOutput('histplot'),
    DT::dataTableOutput(outputId = "site_table")
  )
)

服务器文件:

# 
server <- function(input, output) {

  DF <- reactive({

    df2 %>%
      select(Site, Day, Year, Unit, Value = input$y) %>%
      filter(Site %in% input$site) %>%
      na.omit()

  })

  output$histplot <- renderPlot({
    req(input$site)
    req(input$y)


    p <- ggplot(data = DF(), aes(y = Value, x = Year, label = Site, color = Site)) + 
      geom_point(stat = "identity",
                 size = 3) +
      geom_label_repel(fill = "white",
                       size = 6) +
      scale_x_continuous(limits = c(2005, 2018)) +
      # scale_y_continuous(limits = c(0, max(Var))) +
      theme_bw() +
      theme(panel.grid.major = element_blank(),
            panel.grid.minor = element_blank(),
            legend.position = "none",
            panel.background = element_rect(fill = "floralwhite")

      ) +
      facet_wrap(~.Unit) +
      labs(ylab(input$y))

    print(p)

  }, height=300)

  output$site_table <- DT::renderDataTable({
    req(input$site)
    req(input$y)


    DT::datatable(data = DF(),
                  options = list(pageLength = 10),
                  rownames = FALSE)
  })

}

shinyApp(ui, server)

当我在本地运行ShinyApp(ui,服务器)时,一切看起来都很好。

在RStudio中使用“运行应用程序”按钮时,出现以下消息:

Warning: Error in serverFuncSource: server.R returned an object of unexpected type: list
  [No stack trace available]
Error in serverFuncSource() : 
  server.R returned an object of unexpected type: list

当我使用RStudio中的“发布”按钮发布应用程序时,Web文档开始加载,但随后“灰显”并显示“与服务器断开连接”,并带有重新加载的选项。

检查控制台输出会产生对我不知道如何解释的js错误的引用(也许您可以复制并指导我?)。

感谢您的时间和任何建议! (欢迎提供有关如何解释这些错误的信息)。

0 个答案:

没有答案