我正在尝试在tabBox
内为特定的tabPanel
创建侧边栏效果(非常类似于shinyDashboardPlus
仅用box来完成),但并非如此使用mainPanel
和sidebarPanel
可以达到预期效果。
代码:
library(shiny)
library(shinydashboard)
header <- dashboardheader()
sidebar <- dashboardSidebar()
body <- dashboardBody(
useShinyjs(),fluidRow(
div(id = "TimingBox",tabBox(id = "Timing",tabPanel("Tab 1",mainPanel(
plotOutput("plot1")
),div(id ="Sidebar",sidebarPanel(
"Look here"
)
)
),tabPanel("Tab 2"),title = p("Status",actionLink("Link",NULL,icon = icon("plus-square-o"))),width = 4,selected = "Tab 1"
)
)
)
)
ui <- dashboardPage(header,sidebar,body)
server <- function(input,output) {
shinyjs::hide(id = "Sidebar")
observeEvent(input$Link,{
shinyjs::toggle(id = "Sidebar")
})
set.seed(122)
histdata <- rnorm(500)
output$plot1 <- renderPlot({
data <- histdata[seq_len(50)]
hist(data)
})
}
shinyApp(ui,server)
ShinyDashboardPlus带有侧边栏的框(单击i符号):
更新的代码:
我已经做了一些工作,发现我缺少sidebarLayout
()。但是,我仍然希望
- 要叠加在mainPanel顶部的sideBar
-
将sideBar的高度与mainPanel相同。
library(shiny) library(shinydashboard) header <- dashboardheader() sidebar <- dashboardSidebar() body <- dashboardBody( useShinyjs(),sidebarLayout( div(id = "Sidebar",style = "z-index: 1000;",sidebarPanel("There are currently 20 overdue here",width = 6) ),mainPanel(plotOutput("plot1"),width = 12) ) ),icon = icon("plus-square-o")),actionLink("Link2",icon = icon("search"))),server)