闪亮的应用程序不会在仪表板中显示 ggplot

Shiny App wont display ggplot in dashboard

对于仪表板,我使用的是 shinydashboard 包。仪表板的正文部分是这样的:

body <- dashboardBody(
  fluidRow(
    column(width = 12,
           ###Sidebar Tabs
           #Dashboard Tab Content
           tabItems(
             tabItem(tabName = "dashboard",
                     #Graph of Summary Stats
                     box(
                       title = "Summary Stats",
                       status = "info",
                       plotOutput(
                         outputId = "plot1", height = 250)
                     )

然后 UI 和服务器函数是这样的:

##User Interface Using Dashboard Function
ui <- dashboardPage(
  skin = "yellow",
  header,
  sidebar,
  body
)

##Server
server <- function(input, output) { 
  output$plot1 <- renderPlot({
    p <-ggplot(jobForm, aes(x = `Last Name`, y = Stats)) + geom_point()
    print(p)
  })
  }

我希望我正在绘制的图表出现在我制作的其中一个框中,但我觉得我错过了一些东西,因为它没有出现。 ggplot 代码在应用程序之外独立运行。有什么想法吗?

我尝试了以下代码,它适用于虹膜数据:

library(shiny)
library(shinydashboard)
library(ggplot2)

body <- dashboardBody(
        fluidRow(
       column(width = 12,
       ###Sidebar Tabs
       #Dashboard Tab Content
       tabItems(
         tabItem(tabName = "dashboard",
                 #Graph of Summary Stats
                 box(
                   title = "Summary Stats",
                   status = "info",
                   plotOutput(
                     outputId = "plot1", height = 250)
       ))))))   


sidebar<- dashboardSidebar(width = 350,
             sidebarMenu(id="tabs",
                         menuItem("Home page", tabName="dashboard", selected=TRUE)))

server <- function(input, output) { 
  output$plot1 <- renderPlot({
  p <-ggplot(iris, aes(x =Sepal.Length, y = Sepal.Width)) + geom_point()
  print(p)
  })}

ui <- dashboardPage(
 skin = "yellow",
 dashboardHeader(title = "Hello",titleWidth = 350),
 sidebar,
 body)

shinyApp(ui,server)

可能是你的数据有问题!