闪亮的应用程序仅在闪亮服务器上部分运行

时间:2019-10-21 12:32:28

标签: r shiny

我是新手,并编写了我的第一个应用程序,以根据一些健康数据绘制一些图形。该应用程序可以像我在本地想象的那样运行,但是当我将其部署在shinyapps.io上时,我仅在第三个选项卡上获得了一个图(运行正常)。但是,前2个选项卡上的绘图无法提供任何信息,即使它需要的数据来自我也已上传的同一文件。

是否有明显的东西我已经错过或做了,以至于无法生成前3个图?

library(tidyverse)
library(shiny)
library(lubridate)


ERAS <- readRDS("ERAS.rda")

ERAS_yearly <- ERAS %>% 
  arrange(year_m) %>% 
  mutate(DoSdate = ymd(year_m), yearDoS = year(DoSdate), monthDoS = month(DoSdate)) %>%
  group_by(yearDoS) %>%
  summarise(year_meanLOS = mean(Postop_LOS),
            year_meanAll3 = mean(All_3 == T, na.rm = T),
            year_AKI = mean(AKI_pos == T, na.rm = T))

# User Interface

ui <- fluidPage(

  titlePanel("NERCI Data"),

  sidebarLayout(

    sidebarPanel(
      print("Choose the following for graphs on Tabs 1 and 2:"),

      sliderInput("year", "Select Year:", animate = T,
                            min = 2016, max = 2019, value = 2016, sep = ""),

      checkboxGroupInput("approach", "Surgical Approach", c("Laparoscopic", "Lap-assisted", "Converted to open", "Open"),
                       selected = c("Laparoscopic", "Lap-assisted", "Converted to open", "Open")),

      print("Choose the following for graph on Tab 3:"),

      selectInput("x_axis", "Choose x axis",
                  c("Surgical Risk" = "Risk", 
                     "Obesity Class" = "Obesity", 
                     "ASA-PS" = "ASA",
                     "Anaemia" = "Anaemia",
                     "Acute Kidney Injury" = "AKI_pos",
                     "DrEaming Goals" = "All_3",
                     "Surgical Approach" = "Sx_Approach",
                     "POMS on Day 3" = "posPOMS3",
                     "POMS on Day 5" = "posPOMS5",
                     "Re-operation for Leaks" = "Reoperation_Leak",
                     "Re-operation for Other" = "Reoperation_Other",
                     "ICU Admission" = "ICU_Admission"),
                   selected = "Surgical Risk"),

      selectInput("y_axis", "Choose y axis", 
                 c("Total Post-op Length of Stay" = "Postop_LOS",
                     "SHDU Length of Stay" = "HDU_LOS")),

      selectInput("extra_filter", "Choose additional info",
                 c("Surgical Approach" = "Sx_Approach",
                   "Surgical Risk" = "Risk",
                   "Obesity Class" = "Obesity"),
                 selected = "Surgical Approach"),

      dateRangeInput("date", "Choose Date Range of Data to display",
                     start = "2016-02-01", end = Sys.Date(),
                     min = "2016-02-01", max = Sys.Date())

                      ),
    mainPanel(
      tabsetPanel(
        tabPanel("DrEaMing", 
                 plotOutput(outputId = "LOS_plot"),
                 plotOutput(outputId = "All3_plot")),

        tabPanel("AKI Data",
                 plotOutput(outputId = "AKI_plot")),

        tabPanel("Length of Stay Data",
                plotOutput(outputId = "LOS_overall"))
      )
    )
  )
)

# Server

server <- function(input, output){

  output$LOS_plot <- renderPlot({

    plot1a <- ERAS %>% filter(Sx_Approach %in% input$approach) %>% 
      arrange(year_m) %>% 
      mutate(DoSdate = ymd(year_m), yearDoS = year(DoSdate), monthDoS = month(DoSdate)) %>% 
      filter(yearDoS == input$year) %>%
      group_by(year_m) %>%
      mutate(mean_LOS = mean(Postop_LOS)) %>% 
      ggplot(aes(x = monthDoS, y = mean_LOS)) + geom_line(colour = "#A8659C", size = 1.5) +
      geom_hline(data = ERAS_yearly[ERAS_yearly$yearDoS == input$year, ], aes(yintercept = year_meanLOS), alpha = 0.4, colour = "#323232") + 
      scale_x_continuous(limits = c(1, 12), breaks = c(1:12)) +
      scale_y_continuous(limits = c(0,30), minor_breaks = 1) +
      theme(aspect.ratio = 0.4) + xlab("Month") + ylab("Days") + ggtitle("Mean Length of Stay over Time")

    plot1a

  })
  output$All3_plot <- renderPlot({

    plot1b <- ERAS %>% filter(Sx_Approach %in% input$approach) %>%
      arrange(year_m) %>% 
      mutate(DoSdate = ymd(year_m), yearDoS = year(DoSdate), monthDoS = month(DoSdate)) %>% 
      filter(yearDoS == input$year) %>% group_by(year_m) %>%
      mutate(mean_All3 = mean(All_3 == T, na.rm = T)) %>%
      ggplot(aes(x = monthDoS, y = mean_All3)) + geom_line(colour = "#116133", size = 1.5) + 
      geom_hline(data = ERAS_yearly[ERAS_yearly$yearDoS == input$year, ], aes(yintercept = year_meanAll3), alpha = 0.4, colour = "#323232") +
      scale_x_continuous(limits = c(1, 12), breaks = c(1:12)) +
      scale_y_continuous(labels = scales::percent, limits = c(0, 1)) +
      theme(aspect.ratio = 0.4) + xlab("Month") + ylab("Percentage") + ggtitle("Patients Achieving All Three ERAS Goals")

    plot1b

  })
  output$AKI_plot <- renderPlot({

    plot2 <- ERAS %>% filter(Sx_Approach %in% input$approach) %>%
      arrange(year_m) %>% 
      mutate(DoSdate = ymd(year_m), yearDoS = year(DoSdate), monthDoS = month(DoSdate)) %>% 
      filter(yearDoS == input$year) %>% group_by(year_m) %>%
      mutate(mean_AKI = mean(AKI_pos == T, na.rm = T)) %>%
      ggplot(aes(x = monthDoS, y = mean_AKI)) + geom_line(colour = "#FDDB2E", size = 1.5) + 
      geom_hline(data = ERAS_yearly[ERAS_yearly$yearDoS == input$year, ], aes(yintercept = year_AKI), alpha = 0.4, colour = "#323232") +
      scale_x_continuous(limits = c(1, 12), breaks = c(1:12)) +
      scale_y_continuous(labels = scales::percent, limits = c(0, 1)) +
      theme(aspect.ratio = 0.4) + xlab("Month") + ylab("Percentage") + ggtitle("Percentage of Patients with Post-op AKI")

    plot2

  })
  output$LOS_overall <- renderPlot({
    x <- input$x_axis
    y <- input$y_axis
    extra <- input$extra_filter

    ERAS <- filter(ERAS, DoS >= input$date[1] & DoS <= input$date[2])

    plot03 <- ggplot(data = ERAS, aes_string(x = x, y = y)) + 
      geom_jitter(aes_string(colour = extra), alpha = 0.5, size = 5) +
      geom_boxplot(alpha = 0.5) +
      ggtitle("Length of Stay Post-op") + xlab(x) + ylab("Length of Stay") +
      theme(aspect.ratio = 0.6)

    plot03

  })
}

shinyApp(ui = ui, server = server)


0 个答案:

没有答案