由于“ app.R未返回shiny.appobj对象”,因此无法部署Rshiny应用程序。

时间:2019-11-29 10:44:34

标签: r shiny

我的闪亮应用程序在运行时可以正常运行,但是当我尝试部署它时却出现错误。

我创建了一个名为app.R的文件,其中包含ui和服务器组件。这是代码:

library("shiny")
library("readxl")
library(dplyr)
library(ggplot2)
library(reshape)
library(lattice)
library("stringr")

#setwd("/Users/s0m05ly/Downloads/")

data <- read_excel("Store_cbsa_data_20191129.xlsx")
data_cbsa <- read_excel("cbsa_list_20191129.xlsx")
cbsa_list = (unique(data_cbsa$CBSA))
total_df <- data.frame()
#total_df2 <- data.frame()

if (interactive()) {

  ui <- fluidPage(

    sidebarLayout(

      sidebarPanel(

        selectInput("CBSA", "Choose CBSA(s):",
                    choices = cbsa_list,
                    multiple = TRUE
        )

      ),

      mainPanel(
        fluidRow(
          column(12, plotOutput("contents"))
        ),
        fluidRow(
          column(12, plotOutput("contents2"))
        ),
        fluidRow(
          column(12, plotOutput("contents3"))
        ),
        fluidRow(
          column(12, plotOutput("contents4"))
        ),
        fluidRow(
          column(12, plotOutput("contents5"))
        ),
        fluidRow(
          column(12, plotOutput("contents6"))
        )
      )
    )
  )


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



    df_subset <- reactive({

      cbsa_val <- input$CBSA
      #browser()
      len = length(cbsa_val)
      cbsa_set <- strsplit(as.character(cbsa_val[[len]]),",")
      if (len>0){
        cbsa_set <- data.frame(cbsa_set)
        names(cbsa_set)[1]<- paste("CBSA_Name")
        cbsa_set$CBSA_Name = str_trim(cbsa_set$CBSA_Name, side = "left")

        a <- data%>%filter(CBSA %in% (cbsa_set$CBSA_Name))
        #browser()
        b<-cbind(a, cbsa_new=cbsa_val[[len]])
        #browser()
        return(b)
      }
      else {
        return (cbind(data, cbsa_new="Chain level"))
      }
    })


    output$contents = renderPlot({
      df_s = df_subset()
      total_df <<- rbind(total_df, df_s)
      total_df2 <- total_df%>%filter(total_df$cbsa_new %in% (c("Chain level",input$CBSA)))%>% droplevels()
      densityplot(~ total_df2$revenue_meth2, group = total_df2$cbsa_new, data = total_df2, xlab="revenue_meth2",auto.key = TRUE)

    })
    output$contents2 = renderPlot({
      total_df2 <- total_df%>%filter(total_df$cbsa_new %in% (c("Chain level",input$CBSA)))%>% droplevels()
      densityplot(~ total_df2$UNC_perc, group = total_df2$cbsa_new, data = total_df2, xlab="UNC_perc",auto.key = TRUE)

    })
    output$contents3 = renderPlot({
      total_df2 <- total_df%>%filter(total_df$cbsa_new %in% (c("Chain level",input$CBSA)))%>% droplevels()
      print(input$CBSA)
      densityplot(~ total_df2$Market_share, group = total_df2$cbsa_new, data = total_df2,xlab="Market_share", auto.key = TRUE)

    })
    output$contents4 = renderPlot({
      total_df2 <- total_df%>%filter(total_df$cbsa_new %in% (c("Chain level",input$CBSA)))%>% droplevels()
      densityplot(~ total_df2$CTI_index, group = total_df2$cbsa_new, data = total_df2,xlab="CTI_index", auto.key = TRUE)

    })
    output$contents5 = renderPlot({
      total_df2 <- total_df%>%filter(total_df$cbsa_new %in% (c("Chain level",input$CBSA)))%>% droplevels()
      densityplot(~ total_df2$Average_Income, group = total_df2$cbsa_new, data = total_df2,xlab="Average_Income", auto.key = TRUE)

    })
    output$contents6 = renderPlot({
      total_df2 <- total_df%>%filter(total_df$cbsa_new %in% (c("Chain level",input$CBSA)))%>% droplevels()
      densityplot(~ total_df2$Population_Density, group = total_df2$cbsa_new, data = total_df2,xlab="Population_Density", auto.key = TRUE)

    })
  }
}

shinyApp(ui, server)

这是我得到的错误:

app.R did not return a shiny.appobj object.

为什么会出现此错误?我之前尚未部署过该应用程序,因此不确定此处缺少什么。

0 个答案:

没有答案