首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我要plot1出现在tab1上,plot2出现在tab2上

我要plot1出现在tab1上,plot2出现在tab2上
EN

Stack Overflow用户
提问于 2019-07-13 16:26:13
回答 1查看 33关注 0票数 1

我有一个静态显示板,它有两个标签。目前,plot1和plot2都出现在tab1和tab2上。

我希望plot1只出现在tab1上。我希望plot2只出现在tab2上。

如果你需要更多的信息,请告诉我。

代码语言:javascript
复制
First plot data: 
structure(list(gender = structure(c(1L, 2L, 1L, 2L, 1L, 2L), .Label = c("female", 
"male"), class = "factor"), subject = structure(c(1L, 1L, 2L, 
2L, 3L, 3L), .Label = c("math", "reading", "writing"), class = "factor"), 
    avg_score = c(63.6332046332046, 68.7282157676349, 72.6081081081081, 
    65.4730290456432, 72.4671814671815, 63.3112033195021)), class = "data.frame", row.names = c(NA, 
-6L))

Second plot data:
structure(list(race_ethnicity = structure(c(1L, 2L, 3L, 4L, 5L, 
1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L), .Label = c("1", "2", 
"3", "4", "5"), class = "factor"), subject = structure(c(1L, 
1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L), .Label = c("math", 
"reading", "writing"), class = "factor"), avg_score = c(61.6292134831461, 
63.4526315789474, 64.4639498432602, 67.3625954198473, 73.8214285714286, 
64.6741573033708, 67.3526315789474, 69.1034482758621, 70.030534351145, 
73.0285714285714, 62.6741573033708, 65.6, 67.8275862068966, 70.1450381679389, 
71.4071428571429)), class = "data.frame", row.names = c(NA, -15L
))




ui <- dashboardPage(
  dashboardHeader(title = "Student Performance"),
  dashboardSidebar(
    sidebarMenu(
      menuItem("Demographics", tabName = "demographics", icon = icon("id-card")),
      menuItem("Programs", tabName = "programs", icon = icon("folder")))),

  dashboardBody(
    tabItems(
      tabItem(tabName = "demographics",
          fluidRow(box(plotOutput("p1")),
      tabItem(tabName = "programs",
          fluidRow(box(plotOutput(("p2"))))))))))

server <- function(input, output){
output$p1 <- renderPlot({ggplot(df1, aes(x = gender, y = avg_score))+
    geom_col(aes(fill = subject), width = 0.7)})

output$p2 <- renderPlot({ggplot(df2, aes(x = race_ethnicity, y = avg_score))+
    geom_col(aes(fill = subject), width = 0.7)})}

shinyApp(ui, server)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-07-13 21:58:33

我认为这可能只是你的括号放置在你的UI。这似乎是可行的:

代码语言:javascript
复制
ui <- dashboardPage(
  dashboardHeader(title = "Student Performance"),
  dashboardSidebar(
    sidebarMenu(
      menuItem("Demographics", tabName = "demographics", icon = icon("id-card")),
      menuItem("Programs", tabName = "programs", icon = icon("folder")))),

  dashboardBody(
    tabItems(
      # Demographic tab content
      tabItem(tabName = "demographics",
              fluidRow(box(plotOutput("p1")))
              ),

      # Programs tab content
      tabItem(tabName = "programs",
              fluidRow(box(plotOutput("p2")))
              )
    )
  )
)
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57020910

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档