首页 > 解决方案 > 闪亮的仪表板产生此错误:您将函数作为全局数据传递。您是否拼错了 `ggplot()` 中的 `data` 参数

问题描述

我在哪里犯错?是什么导致了这个错误?谢谢。以下是完整的错误消息: Listening on http://127.0.0.1:7891 警告:错误:您将函数作为全局数据传递。你把data论点拼错了吗ggplot()

library(shiny)
library(dplyr)
library(ggplot2)

COV <- read.csv('pathway', stringsAsFactors = F)

ui <- fluidPage(
  sidebarLayout(
    sidebarPanel(
      selectInput("selectInput1",
                  "Select PID:",choices = unique(COV$PID),
                  selected = "1000"),
      selectInput("selectInput2",
                  "Select Parent Identifier",
                  choices = unique(COV$M_CM),
                  selected = "1"),
      selectInput("selectInput3",
                  "Select x variable:",
                  choices = names(COV),
                  selected = "StartDate"),
      selectInput("selectInput4",
                  "Select y variable:",
                  choices = names(COV),
                  selected = "COV_WOR")
    ),
    mainPanel(
      plotOutput('plot')
    )
  )
)

server <- function(input,output){
  
  selectedData <- reactive({
    COV[COV$PID == input$selectInput1 & COV$M_CM == input$selectInput2, c(input$selectInput3, input$selectInput4)]
  })
  
  
  output$plot <- renderPlot({
    # Use aes_string for column names stored in strings
    p <- ggplot(selectedData, aes_string(x = input$selectInput3, y = input$selectInput4))+
      geom_line()
    
    p
  })
}

shinyApp(ui,server)

标签: rggplot2shinyshinydashboard

解决方案


推荐阅读