簡體   English   中英

閃亮:如何增加tabsetPanel的寬度以覆蓋sidebarPanel右側的整個區域?

[英]Shiny: How to increase the width of tabsetPanel to cover the whole area to the right of the sidebarPanel?

我想創建一個閃亮的應用程序,其中有一個sidebarPanel和tabesetPanel。

我使用以下代碼創建了應用

library(shiny)
library(ggplot2)
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
h1("Shiny app"), 
tags$hr(),
h2("several options here"), 
width =2),
mainPanel(uiOutput("tb"))
)
)
server <- function(input,output){
output$diamonds1 <- renderPlot({
ggplot(diamonds, aes(x=carat, y=price, col=clarity)) + 
                     geom_point(alpha=0.5)+ facet_wrap(~color, scales="free")
})
output$diamonds2 <- renderPlot({
ggplot(diamonds, aes(x=carat, y=price, col=clarity)) + 
                     geom_point(alpha=0.5)+ facet_wrap(~cut, scales="free")
})
output$info <- renderPrint({
nearPoints(diamonds, input$plot_click, threshold = 10, maxpoints = 1,
           addDist = TRUE)
})    
output$tb <- renderUI({
tabsetPanel(tabPanel("First plot", 
                     plotOutput("diamonds1")),
            tabPanel("Second plot", 
                     plotOutput("diamonds2", click = "plot_click"), 
                     verbatimTextOutput("info")))      
})
}
shinyApp(ui = ui, server = server)  

我希望tabsetPanel覆蓋sidebarPanel右側的整個區域。

根據此問題的答案 ,我嘗試了以下方法

div(, class ="span12") 

),  style='width: 1000px;)

但是,選項卡集面板和繪圖仍不能覆蓋sidebarPanel右側的整個區域。

有什么建議怎么做?

更新

感謝@K。 羅德(Rohde)的回答,該圖現在覆蓋了sidebarPanel旁邊頁面的整個高度,但仍然沒有覆蓋整個寬度

在此處輸入圖片說明

編輯:很抱歉沒有檢查我的第一個答案。 但是這是可行的:

由於某種原因, plotOutputheight = "100%"不起作用的plotOutput被破壞了,否則可以解決。 但是您可以手動添加css3,它根據窗口大小使用...vh縮放繪圖。

碼:

library(shiny)
library(ggplot2)
ui <- fluidPage(
  sidebarLayout(
    sidebarPanel(
      h1("Shiny app"), 
      tags$hr(),
      h2("several options here"), 
      width =2),
    mainPanel(
      uiOutput("tb")
    )
  )
)
server <- function(input,output, session){
  output$diamonds1 <- renderPlot({
    ggplot(diamonds, aes(x=carat, y=price, col=clarity)) + 
      geom_point(alpha=0.5)+ facet_wrap(~color, scales="free")
  })
  output$diamonds2 <- renderPlot({
    ggplot(diamonds, aes(x=carat, y=price, col=clarity)) + 
      geom_point(alpha=0.5)+ facet_wrap(~cut, scales="free")
  })
  output$info <- renderPrint({
    nearPoints(diamonds, input$plot_click, threshold = 10, maxpoints = 1,
               addDist = TRUE)
  })    
  output$tb <- renderUI({
    tabsetPanel(
      tabPanel("First plot", 
                         tags$head(tags$style(type = "text/css", "#diamonds1 {height:95vh !important;}")),
                         plotOutput("diamonds1")),
                tabPanel("Second plot", 
                         tags$head(tags$style(type = "text/css", "#diamonds2 {height:80vh !important;}")),
                         plotOutput("diamonds2", click = "plot_click"), 
                         verbatimTextOutput("info")))      
  })
}
shinyApp(ui = ui, server = server)  

我承認,這更多是一種解決方法。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM