es.davy.ai

Preguntas y respuestas de programación confiables

¿Tienes una pregunta?

Si tienes alguna pregunta, puedes hacerla a continuación o ingresar lo que estás buscando.

El ajuste dinámico de altura del tabpanel no funciona con infobox.

Estoy creando un panel de control con shiny y quiero utilizar infobox dentro de un panel de pestañas. Sin embargo, la altura del panel no se ajusta dinámicamente a la altura del infobox. Si integro un gráfico en un panel, se ajusta automáticamente.

Mi código se ve así:

library("shiny")
library("shinydashboard")
library("shinydashboardPlus")

ui <- dashboardPage(
    header = dashboardHeader()
    ,sidebar = dashboardSidebar()
    ,body = dashboardBody(

    tabBox(
        tabPanel(
            title = "Tab1"
            ,infoBoxOutput(outputId = "ibo")
        )
        ,tabPanel(
            title = "Tab2"
            ,plotOutput(outputId = "po")
        )
        ,width = 12
    )

)
)

server <- function(input, output) {

output$ibo <- renderInfoBox({
    infoBox(
        title = "Infobox"
        ,value = 42
    )
})

output$po <- renderPlot({
    plot(mtcars$mpg, mtcars$cyl)
})

}

shinyApp(ui = ui, server = server)

¿Cómo puedo ajustar la altura del panel de pestañas a la altura del infobox?

Tags:  , , , ,

Answer

  1. Avatar for davy.ai

    Una solución es agregar el argumento heightStyle a la función tabBox y establecerlo en "content". Esto hará que la altura del panel de pestañas se ajuste al contenido dentro de él, incluyendo el infobox.

    Entonces, el código modificado se vería así:

    library("shiny")
    library("shinydashboard")
    library("shinydashboardPlus")
    
    ui <- dashboardPage(
      header = dashboardHeader(),
      sidebar = dashboardSidebar(),
      body = dashboardBody(
        tabBox(
          tabPanel(
            title = "Tab1",
            infoBoxOutput(outputId = "ibo")
          ),
          tabPanel(
            title = "Tab2",
            plotOutput(outputId = "po")
          ),
          width = 12,
          heightStyle = "content" # Agregar esta línea
        )
      )
    )
    
    server <- function(input, output) {
    
      output$ibo <- renderInfoBox({
        infoBox(
          title = "Infobox",
          value = 42
        )
      })
    
      output$po <- renderPlot({
        plot(mtcars$mpg, mtcars$cyl)
      })
    
    }
    
    shinyApp(ui = ui, server = server)
    

Comments are closed.