3

I am trying to resize a plotlyOutput in a shiny app but changing the height parameters doesnt seem to affect the plot size, after updating today to R 3.4 and updating shiny, and plotly (plotly_4.7.0, ggplot2_2.2.1.9000, shiny_1.0.3 ) I realized that the size of the plot does not change dynamically when resizing the window. I have tried modifying the size of the plot directly using height in plotlyoutput, as well as modifying the $layout$height property from the plotly object,t but it doesnt seem to have any effect on the size of the plots. Here is a sample code.

ui<-fluidPage(
mainPanel(
tabsetPanel(
  tabPanel("tab",
           selectInput("plot","Plot type",c("Box plot"="box","Inidividual cells"="cell","Violin plot"="violin"),"violin"),
           plotlyOutput('Barplot',height = "100px")
           )
    )
  )
)

server<- function(input,output,session){
output$Barplot <- renderPlotly({
bp <- ggplot(mtcars,aes(x=cyl,y=mpg,colour=cyl))+geom_point() 
bp<-plotly_build(bp)
bp$layout$width= 100
bp
})
}
shinyApp(server=server,ui=ui)
0

1 Answer 1

0

Try

plotlyOutput('Barplot')

and

bp <- ggplot(mtcars,aes(x=cyl,y=mpg,colour=cyl))+geom_point() 
ggplotly(bp, height=800) %>% layout(autosize=FALSE)
Sign up to request clarification or add additional context in comments.

4 Comments

It runs fine, but changing the height value doesnt seem to have any effect on the plot
@JorgeKageyama For me it works. Did you remove height="100px" from plotlyOutput ?
I use R 3.3.3, and the same packages as you except that I use the development (Github) version of shiny.
I've just tried with R 3.4.0 and it works as well. Weird. I'm on Windows 7.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.