rstudio / shinydashboard

Shiny Dashboarding framework
https://rstudio.github.io/shinydashboard/
Other
893 stars 298 forks source link

Plotly plot width and height graph within tabBox module #270

Closed jdbarillas closed 5 years ago

jdbarillas commented 6 years ago

Possibly related to #219, but adjustments to the height and width did not solve the problem. It seems to happen with the first plot to be rendered by the module. When the plot is re-rendered by a change in input, the height and width of the plot are correct.

Below is a reproducible example and can also be seen here sporadically.

library(shinydashboard)
library(plotly)

moduleUI <- function(id, data, ...) {
  ns <- NS(id)
  tagList(
    tabBox(side = "right", selected = "Box Plot",
           title = "Box Plot", width = 12,
           # The id lets us use input$tabset1 on the server to find the current tab
           id = "tabset1", height = "450px",

           tabPanel("Box Plot", plotlyOutput(ns("b_plot"), height = "350px", width = '100%'))
    )
  )
}

sidebar <- dashboardSidebar(
  sidebarMenu(
    menuItem("Dashboard", tabName = "dashboard", icon = icon("dashboard"))
  )
)

ui <- dashboardPage(
  dashboardHeader(title = "Basic dashboard"),
  sidebar,
  dashboardBody(
    tabItems(
      tabItem(tabName = "dashboard",
              h2("Dashboard tab content"),
    helpText("Help Text"),
    fluidRow(
      moduleUI("one")
    ),
    tags$br(),
    fluidRow(
      moduleUI("two")
    ),
    tags$br(),
    fluidRow(
      moduleUI("three")
    ),
    tags$br()
    ))
  )
)

testModule <- function(input, output, session, sub_data) {

output$b_plot <- renderPlotly({
    p <- ggplot(data = mtcars, aes(x = as.factor(cyl), y = mpg, fill = as.factor(gear), color = as.factor(gear))) +
      geom_boxplot() 

    ggplotly(p)           
  })
}
server <- function(input, output) {
  callModule(testModule, "one")
  callModule(testModule, "two")
  callModule(testModule, "three")
}
shinyApp(ui, server)
ismirsehregal commented 5 years ago

I can't reproduce the problem using: plotly 4.8.0 2018-07-20 CRAN shiny 1.1.0.9001 2018-10-15 Github shinydashboard * 0.7.0.9000 2018-10-15 Github

You might want to update:

if (!require("devtools"))
  install.packages("devtools")
devtools::install_github("rstudio/shiny")
devtools::install_github("rstudio/shinydashboard")
cpsievert commented 5 years ago

When using ggplotly(), you may have to route the container's height/width the ggplotly() call. See here for an example https://github.com/ropensci/plotly/blob/master/inst/examples/shiny/ggplotly_sizing/app.R