I'm developing an R "shiny" application where it is necessary to pass size parameters (width and height) different to the corresponding defaults, for a leaflet map, for avoiding issues with a relatively large legend. The documentation for leaflet R package pointed out that these parameters could be set directly in the leaflet constructor, however, there are ignored in a shiny application.
For a 'leafletOutput' shiny method, following syntax, leafletOutput("leaflet1", width = 200, height = 200)
, works properly. However, I need such parameters in a 'uiOutput' object where the following syntax uiOutput("leaflet2", width = 200, height = 200)
doesn't produce any error but it doesn't work as expected.
So, I looked at UI Output documentation and I tried out this one approach uiOutput("leaflet2", quoted = TRUE, outputArgs = list(width = 200, height = 200))
without any success. My question is how can I add size parameters in an uiOutput element for a shiny application?
My sample code looks as follows (original is too large):
library(shiny)
library(leaflet)
ui <- fluidPage(
sidebarLayout(
titlePanel(""),
mainPanel(
leafletOutput("leaflet1", width = 200, height = 200),
uiOutput("leaflet2", quoted = TRUE, outputArgs = list(width = 200, height = 200))
)
)
)
server <- function(input, output) {
output$leaflet1 <- renderLeaflet({
m <- leaflet() %>% addTiles()
m
})
output$leaflet2 <- renderUI({
output$leafletMap <- renderLeaflet({
m <- leaflet() %>% addTiles()
m
})
})
}
# Run the application
shinyApp(ui = ui, server = server)
The result looks as follows when above code is run. As it can be observed, in the second render UI object the size parameters are completely ignored.