为什么Shiny不能在服务器上本地运行

时间:2019-07-08 08:24:20

标签: r shiny

我有以下应用程序,当我在本地启动它时,它运行正常,但是在闪亮的服务器上部署时,出现错误。 ggplot对象output$plot1不可见,错误为An error has occurred. Check your logs or contact the app author for clarification.

应用程序在这里https://mateuszskog.shinyapps.io/MALval/

应用代码如下

library(shiny)
library(shinydashboard)
library(leaflet)
library(data.table)
library(ggplot2)
library(rpivotTable)
library(DT)

ui <- pageWithSidebar(
  headerPanel("DMS data Viewer"),
  sidebarPanel(
    fileInput('file1', 'Choose CSV File',
              accept=c('text/csv','text/comma-separated-values,text/plain','.csv')),
    #tags$hr(),

    checkboxInput('header', label = "Header", TRUE),

    fluidRow(
      column(4,radioButtons("xaxisGrp","X-Axis:", c("1"="1","2"="2"))),
      column(4,radioButtons("yaxisGrp","Y-axis:", c("1"="1","2"="2")))
      #column(4,selectInput("colpointsGrp","Grouping:", c("1"="1","2"="2")))
    ),
    radioButtons('sep', 'Separator',
                 c(Comma=',', Semicolon=';',Tab='\t'), ','),
    radioButtons('quote', 'Quote',
                 c(None='','Double Quote'='"','Single Quote'="'"),'"'),
    radioButtons('shower', 'Show first 10 rows',
                 c(Show=10,
                   DoNotShow=FALSE
                 )),
    uiOutput("choose_columns")
  ),
  mainPanel(
    tabsetPanel(
      tabPanel("Data", tableOutput('contents1')),
      tabPanel("Plots",plotOutput("plot1"), plotOutput("plotDist")),
      tabPanel("Descriptive summary", verbatimTextOutput("Descripsummary")),
      tabPanel("Pivot Table", rpivotTableOutput("OverallPivot"))
    )
  )
)


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

  data_set <- reactive({
    inFile <- input$file1

    if (is.null(inFile))
      return(mtcars)

    data_set<-read.csv(inFile$datapath, header=input$header, 
                       sep=input$sep, quote=input$quote, na.string = ".")
    data_set
  })

  output$contents1 <- renderTable({head(data_set(), input$shower)}) #n = input$shower

  observe({
    dsnames <- names(data_set())
    cb_options <- list()
    cb_options[ dsnames] <- dsnames
    updateRadioButtons(session, "xaxisGrp",
                       label = "X-Axis",
                       choices = cb_options,
                       selected = "")
    updateRadioButtons(session, "yaxisGrp",
                       label = "Y-Axis",
                       choices = cb_options,
                       selected = "")
    updateSelectInput(session, "colpointsGrp", label = "Color-Points",
                      choices = cb_options,
                      selected = "")
  })

  output$choose_dataset <- renderUI({
    selectInput("dataset", "Data set", as.list(data_sets))
  })

  output$plot1 = renderPlot(
    {
      df <- data_set()
      gp <- NULL
      if (!is.null(df)){
        xv <- input$xaxisGrp
        yv <- input$yaxisGrp
        #col <- input$colpointsGrp
        if (!is.null(xv) & !is.null(yv) ){ #n = input$shower
          if (sum(xv %in% names(df))>0){ # supress error when changing files
            mdf <- df %>% select(input$xaxisGrp, input$yaxisGrp) #, input$colpointsGrp
            gp <- ggplot(data=mdf) + 
              geom_point(aes_string(x=input$xaxisGrp,y=input$yaxisGrp)) + #, color=input$colpointsGrp)
              ylab(input$yaxisGrp)
          }
        }
      }
      return(gp)
    }
  )

  output$plotDist = renderPlot(
    {
      df <- data_set()
      gp <- NULL
      if (!is.null(df)){
        xv <- input$xaxisGrp

        if (!is.null(xv)){
          if (sum(xv %in% names(df))>0){ # supress error when changing files
            mdf <- melt(df,id.vars=xv)
            gp <- ggplot(data=mdf) + 
              geom_density(aes_string(x=xv))
          }
        }
      }
      return(gp)
    }
  )

  output$OverallPivot <- renderRpivotTable({
    rpivotTable(data = data_set())
  })


  output$contents <- DT::renderDataTable({
    DT::datatable(data_set())       
  })


  output$Descripsummary <- renderPrint({
    summary(data_set())
  })


  output$choose_columns <- renderUI({

    if(is.null(input$dataset))
      return()
    colnames <- names(contents)
    checkboxGroupInput("columns", "Choose columns", 
                       choices  = colnames,
                       selected = colnames)
  }) 
}


shinyApp(ui, server)
  
    

sessionInfo()R版本3.5.1(2018-07-02)平台:i386-w64-mingw32 / i386(32位)在以下环境下运行:Windows> = 8 x64(build     9200)

  
     

Matrix产品:默认

     

语言环境:1 LC_COLLATE = Swedish_Sweden.1252   LC_CTYPE = Swedish_Sweden.1252 [3] LC_MONETARY = Swedish_Sweden.1252   LC_NUMERIC = C [5] LC_TIME = Swedish_Sweden.1252

     

附加的基本软件包:1统计信息图形grDevices utils
  数据集方法基础

     

其他随附的软件包:1 DT_0.7 rpivotTable_0.3.0
  data.table_1.11.8 leaflet_2.0.2 [5] Shinydashboard_0.7.1   bindrcpp_0.2.2 dplyr_0.7.8闪亮_1.2.0 [9]   ggplot2_3.1.0

     

通过名称空间(未附加)加载:1 reshape2_1.4.3
  jsonlite_1.5 rstudioapi_0.8 magrittr_1.5 gtable_0.2.0
  [6] tidyr_0.8.2 hms_0.4.2 utf8_1.1.4 xml2_1.2.0
  支柱_1.3.0 [11] htmltools_0.3.6 forcats_0.3.0
  stringr_1.3.1避风港_2.0.0以后_0.7.5 [16]扫帚_0.5.0   cellranger_1.1.0点阵_0.20-35 htmlwidgets_1.3 tidyselect_0.2.5   [21] plyr_1.8.4 lubridate_1.7.4 mime_0.6
  pkgconfig_2.0.2 R6_2.3.0 [26]摘要_0.6.18
  colorspace_1.3-2 stringi_1.2.4串扰_1.0.0 yaml_2.2.0
  [31] lazyeval_0.2.1 labeling_0.3 fansi_0.4.0
  gdata_2.18.0 tibble_1.4.2 [36] httr_1.3.1
  editor_3.5.1绑定器_0.1.1 cli_1.0.1 withr_2.1.2
  [41] backports_1.1.2 gmodels_2.18.1 xtable_1.8-3
  munsell_0.5.0建模者_0.1.2 [46] Rcpp_1.0.0
  readxl_1.1.0 sourcetools_0.1.7 tidyverse_1.2.1 MASS_7.3-50
  [51] openssl_1.1断言_0.2.0 readr_1.1.1
  gtools_3.8.1 tools_3.5.1 [56] httpuv_1.4.5
  标度_1.0.0 crayon_1.3.4胶水_1.3.0 purrr_0.2.5
  [61] rlang_0.3.0.1 nlme_3.1-137 rvest_0.3.2
  promises_1.0.1 rsconnect_0.8.11 [66] grid_3.5.1

0 个答案:

没有答案