我有一个带有两个选项卡的静态Shinydashboard。当前,plot1和plot2都出现在tab1和tab2上。
我希望plot1仅出现在tab1上。我希望plot2仅出现在tab2上。
如果您需要更多信息,请告诉我。
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)
答案 0 :(得分:1)
我认为这可能只是您在用户界面中的括号位置。这似乎可行:
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")))
)
)
)
)