对于仪表板,我使用的是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代码本身在应用程序之外工作。有什么想法吗?
答案 0 :(得分:0)
我尝试了以下代码,它适用于虹膜数据:
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)
也许问题来自您的数据!