admin管理员组

文章数量:1400201

I am testing a modal in the Shiny app I am developing. I noticed that when the modal opens or closes, the plotOutput briefly resizes, which is a bit distracting.

I'd like to ensure that users are not distracted by minor visual shifts like this. I am wondering how to prevent plotOutput from resizing when the modal appears or disappears in Shiny.

The minimal reproducible example is attached below:

library(shiny)
library(bslib)
library(ggplot2)

ui <- page_fillable(
    
    theme   = bs_theme(version = 5),
    
    div(
        tags$span(
            style = "vertical-align: bottom;",
            actionButton("b", "", icon = icon("question"))
        )
    ),
    
    card(
        plotOutput(outputId = "iris")
    )
)

server <- function(input, output, session) {
    observeEvent(input$b, {
        showModal(
            modalDialog(
                title = "Somewhat important message",
                
                card(
                    card_header("Placeholder")
                ),
                
                easyClose = TRUE,
                size = "l",
                footer = modalButton("Ok")
            ))
    })
    
    
    output$iris <- renderPlot({
        iris |> 
            ggplot(aes(x = Sepal.Length, y = Sepal.Width, colour = Species)) +
            geom_line() +
            theme_minimal()
    })
}

shinyApp(ui, server)

I am testing a modal in the Shiny app I am developing. I noticed that when the modal opens or closes, the plotOutput briefly resizes, which is a bit distracting.

I'd like to ensure that users are not distracted by minor visual shifts like this. I am wondering how to prevent plotOutput from resizing when the modal appears or disappears in Shiny.

The minimal reproducible example is attached below:

library(shiny)
library(bslib)
library(ggplot2)

ui <- page_fillable(
    
    theme   = bs_theme(version = 5),
    
    div(
        tags$span(
            style = "vertical-align: bottom;",
            actionButton("b", "", icon = icon("question"))
        )
    ),
    
    card(
        plotOutput(outputId = "iris")
    )
)

server <- function(input, output, session) {
    observeEvent(input$b, {
        showModal(
            modalDialog(
                title = "Somewhat important message",
                
                card(
                    card_header("Placeholder")
                ),
                
                easyClose = TRUE,
                size = "l",
                footer = modalButton("Ok")
            ))
    })
    
    
    output$iris <- renderPlot({
        iris |> 
            ggplot(aes(x = Sepal.Length, y = Sepal.Width, colour = Species)) +
            geom_line() +
            theme_minimal()
    })
}

shinyApp(ui, server)
Share Improve this question edited Mar 26 at 8:16 Grasshopper_NZ asked Mar 26 at 6:23 Grasshopper_NZGrasshopper_NZ 8875 silver badges15 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

The problem is with page_fillable, try page_fixed instead.


If you want to keep the fillable behavior of the components, but want to isolate the plotly-Output, you can wrap it like

card(
    htmltools::div(style="height:900px !important;", plotOutput(outputId = "iris", height="900px"))
  )

本文标签: rHow to prevent plotOutput from resizing when a modal opens or closes in ShinyStack Overflow