I'm making an R Shiny application that uses a choropleth to display some data. The plotly version works well, but I can't find how to adjust its sizing to make full use of the space.
It always looks square-ish, I'd want a rectangle that's as wide as the div that the plot is made in.
Here is a small example app:
library(shiny)
library(plotly)
country_data <- data.frame(
country_short = c("DEU", "USA", "BRA", "CAN", "MEX"),
points = c(10, 20, 30, 40, 50)
)
ui <- fluidPage(
div(style="width:1400px",
plotlyOutput("choro")
)
)
server <- function(input, output, session) {
output$choro <- renderPlotly({
plot_ly(country_data,
width = 1400,
type = "choropleth",
z = ~ points,
locations = ~ country_short,
marker = list(
line = list(
color = "white"
)
),
showscale = F
) %>%
layout(geo = list(
landcolor = rgb(0.9, 0.9, 0.9),
countrycolor = "white",
coastlinecolor = "white",
showland = T,
showcountries = T,
showframe = F,
projection = list(type = "Mercator"),
margin = list(l = 0, r = 0)
)
)
})
}
shinyApp(ui, server)
I'd expect the plot to be 1400px wide, but when I inspect element it, the width is 670px. How can I change this, either in R with plotly options, or with CSS?
%>% layout( width = 1400, height = 800, geo = list(...
as per this - no need for adiv
in your ui, just useui <- fluidPage(plotlyOutput("choro"))
. I will just answer as a comment, since it's a duplicate question.