-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
plot is stretched when window is resized #1129
Comments
I think this is the behavior you're looking for (the default shinyApp(
ui = page_sidebar(
sidebar = sidebar(
actionButton("newplot", "New plot")
),
plotOutput("plot", width = 400, fill = FALSE)
),
server = function(input, output) {
output$plot <- renderPlot({
input$newplot
# Add a little noise to the cars data
cars2 <- cars + rnorm(nrow(cars))
plot(cars2)
},
width = 400)
}
) |
That works for this example but in my actual use case I need to set the width on the server side using a function. Here is a better reprex shinyApp(
ui = page_sidebar(
sidebar = sidebar(
actionButton("newplot", "New plot")
),
plotOutput("plot", fill = FALSE)
),
server = function(input, output) {
counter <- reactiveValues(n = 1)
observeEvent(input$newplot, {
counter$n <- counter$n + 1
})
output$plot <- renderPlot({
input$newplot
# Add a little noise to the cars data
par(mfrow = c(1,counter$n))
for(i in 1:counter$n){
cars2 <- cars + rnorm(nrow(cars))
plot(cars2)
}
},
width = function(){
400*counter$n
})
}
)
|
In that case, you could set |
No I want to adjust the width of the plot output based on the calculation I do on the server side and I want it to adjust appropriately to changes in window size like it does with basic |
In that case, you'll want a |
@cpsievert what you supplied is a useful workaround but I think that bslib is still not behaving as expected. Why doesn't it respect the width that is set it I switched from plain shiny to access some of the awesome theming features that bslib has but it would be helpful if these sorts of differences were minimized and or explained. |
That's true, I'm not sure we'd change the behavior at this point, but we could do more to document difference |
Describe the problem
If I create a plot with a width specified in
renderPlot
it works as expected when the page first renders. But if I resize the page the plot image is stretched to fill the whole space. If I generate a new plot it has the expected width again. In my actual use case this also happens after the first time an actionButton is pressed which is more problematic than if it only ever happened with window resizing.Before resize
After resize
Session Info
The text was updated successfully, but these errors were encountered: