简体   繁体   中英

Shiny App wont display ggplot in dashboard

For the dashboard, I am using the shinydashboard package. The body section of the dashboard is this:

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)
                     )

And then the UI and Server function is this:

##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)
  })
  }

I want the graph I'm plotting to appear in one of the boxes I made, but I feel like I'm missing something since it's not showing up. The ggplot code works outside of the app, by itself. Any ideas?

I tried the following code and it works for me with the iris data :

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)

Maybe the problem comes from your data !

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM