Why my graph plot don't fill the column space?

Hello, guys!

This is my first time with Shiny and I think I still don't get how the "layout" works.

My intention is to create a website and I can't position things where I want.

What I have:

How can I improve the width of my graph till the select options? And how can put the select options one under another?

Part of my code:

                        fluidRow(
                                  column(conditionalPanel(
                                         'input.dataset === "Coop_ativas"',
                                          checkboxGroupInput("show_vars", "Selecione as variƔveis:",
                                                              names(Coop_ativas), selected = names(Coop_ativas))), 
                                         width = 4),
                                  
                                  column(selectizeInput("id_m_f", "Matriz (1) ou Filial (2):",
                                                      c("Todas",unique(as.character(Coop_ativas$identificador_matriz_filial))), selected = "Todas",
                                                      options = list(placeholder = 'Todas')), 
                                          selectizeInput("cnae_fiscal", "Cnae Fiscal Principal:",
                                                      c("Todas",str_sort(unique(as.character(Coop_ativas$cnae_fiscal)))), selected = "Todas",
                                                      options = list(placeholder = 'Todas')), 
                                          selectizeInput("desc_cnae","DescriĆ§Ć£o CNAE (divisĆ£o) Principal:",
                                                      c("Todas",str_sort(unique(as.character(Coop_ativas$descricao_cnae_divisao)))), selected = "Todas",
                                                      options = list(placeholder = 'Todas')), 
                                          # selectInput("muni", "MunicĆ­pio:",
                                          #             c("Todas",str_sort(unique(as.character(Coop_ativas$municipio)))),
                                          #                options = list(placeholder = 'Todas')), 
                                          selectizeInput("est", "Estado:",
                                                      c("Todos",str_sort(unique(as.character(Coop_ativas$uf)))), selected = "Todos",
                                                      options = list(placeholder = 'Todos')), 
                                          selectizeInput("regi", "RegiĆ£o:",
                                                      c("Todas",str_sort(unique(as.character(Coop_ativas$regiao)))), selected = "Todas",
                                                      options = list(placeholder = 'Todas')), 
                                         width = 8) 
                                 ),
                        
                        
                         mainPanel(
                                  tabsetPanel(
                                              id = 'dataset',
                                              tabPanel("Coop_ativas", DT::dataTableOutput("mytable1"))
                                              ), 
                                  width = 12),
                        
                        fluidRow( 
                                  column(box(plotOutput("regiao_plot")), width=8), 
                                  column(box(selectizeInput("regiao", "Por RegiĆ£o ou Estado:", 
                                                              choices = list("Estado" = "uf", "RegiĆ£o" = "regiao"),
                                                              selected = "Estado",
                                                              options = list(placeholder = 'Estado'))
                                             ),
                                        box(selectizeInput("estab", "Por tipo de Estabelecimento:", 
                                                        choices = list("Todos" = 3, "Matriz" = 1, "Filial" = 2),
                                                        selected = "Todos", 
                                                        options = list(placeholder = 'Todos'))
                                            ), 
                                  width=4),
                        ),
                 
                        fluidRow(
                                  column( 
                                          box(plotOutput("cnae_plot"), widht = 8), 
                                        width = 8), 
                                  column( 
                                          box(selectizeInput("estad_cnae", "Por Estado:", 
                                                          c("Todos",str_sort(unique(as.character(Coop_ativas$uf)))),
                                                          selected = "Todos", 
                                                          options = list(placeholder = 'Todos'))),
                                          box(selectizeInput("reg_cnae", "Por RegiĆ£o:", 
                                                          c("Todas",str_sort(unique(as.character(Coop_ativas$regiao)))),
                                                          selected = "Todas", 
                                                          options = list(placeholder = 'Todas'))),
                                          box(selectizeInput("estab_cnae", "Por tipo de Estabelecimento:", 
                                                          choices = list("Todas" = 3, "Matriz" = 1, "Filial" = 2),
                                                          selected = "Todos", 
                                                          options = list(placeholder = 'Todos'))),
                                    width = 4)
                                 )

My plot render

output$regiao_plot <- renderPlot({
      
      col <- sym(input$regiao)
      mef <- as.numeric(input$estab)
      reg_cnae <- as.numeric(input$reg_cnae)
      
      Coop_ativas %>% filter(identificador_matriz_filial %in% (if (mef %in% c(1,2)) mef else c(1:2))) %>%
        select(!! col) %>% group_by(!! col) %>% count() %>% 
        arrange(desc(n)) %>% head(10) %>% 
        ggplot(aes(reorder(!! col, n), n), ) + 
        geom_bar(stat="identity", fill="steelblue") +
        geom_text(aes(label=n), vjust=0.5, hjust=-0.5, color="darkgrey", size=3) +
        labs(title = "Top 10 - Quantidade Cooperativas Ativas no Brasil",
             subtitle = "02/2020",
             caption = "Fonte: RFB, tratado por OBSCOOP/USP",
             #tag = "Figure 1",
             x = ifelse(!! col == "uf",  "Estado", "RegiĆ£o"),
             y = "Quantidade") +
        theme_minimal() + theme(plot.title = element_text(hjust = 0.5),
                                plot.subtitle = element_text(hjust = 0.5),
                                plot.caption = element_text(hjust = 0)) +         
        coord_flip() 
    })



Part of my data:

structure(list(cnpj = c("35345543", "2345345", "325445324", 
"235455", "234435", "2345534", "345435", 
"345345", "34545", "345454"), identificador_matriz_filial = c("1", 
"1", "1", "1", "1", "1", "1", "1", "1", "2"), razao_social = c("adadadadadad", 
"bvbvbvbvbvb", "lolololololololo", "wqwqwqwqwqwqwqwqw", "rtrtrtrtrtrt", "iuiuiuiuiu", "kikiikikikiki, "aghaghagah", "kkkkkiiiiiiii"), nome_fantasia = c("", "sdsadasd", "asdasd", 
"COOP asdas", "dsdsds COOPERATIVA", "wqeqwe", "nhnhnh", "sdfsdf", "fsfds", "nhn nhnhn RITA"), descricao_cnae_divisao = c("SERVIƇOS ESPECIALIZADOS PARA CONSTRUƇƃO", 
"SERVIƇOS ESPECIALIZADOS PARA CONSTRUƇƃO", "SERVIƇOS ESPECIALIZADOS PARA CONSTRUƇƃO", 
"SERVIƇOS ESPECIALIZADOS PARA CONSTRUƇƃO", "SERVIƇOS ESPECIALIZADOS PARA CONSTRUƇƃO", 
"SERVIƇOS ESPECIALIZADOS PARA CONSTRUƇƃO", "SERVIƇOS ESPECIALIZADOS PARA CONSTRUƇƃO", 
"SERVIƇOS ESPECIALIZADOS PARA CONSTRUƇƃO", "SERVIƇOS ESPECIALIZADOS PARA CONSTRUƇƃO", 
"FABRICAƇƃO DE PRODUTOS ALIMENTƍCIOS"), cnae_fiscal = c(4399103L, 
4399103L, 4399103L, 4399103L, 4399103L, 4399199L, 4399199L, 4399199L, 
4399199L, 1052000L), idade = c(10, 1, 2, 1, 13, 19, 8, 8, 13, 
41), municipio = c("CONSTANTINA", "BLUMENAU", "PORTAO", "PORTO ALEGRE", 
"SAO LEOPOLDO", "PARINTINS", "CANGUCU", "PASSO FUNDO", "NATAL", 
"NATERCIA"), uf = c("RS", "SC", "RS", "RS", "RS", "AM", "RS", 
"RS", "RN", "MG"), regiao = c("Sul", "Sul", "Sul", "Sul", "Sul", 
"Norte", "Sul", "Sul", "Nordeste", "Sudeste"), data_situacao_cadastral = c("2009-03-06", 
"2018-05-03", "2017-12-21", "2019-01-09", "2006-12-05", "2005-11-03", 
"2011-10-20", "2011-10-14", "2007-01-10", "2001-07-01"), data_inicio_atividade = structure(c(14309, 
17654, 17521, 17905, 13487, 11266, 15267, 15261, 13523, 3284), class = "Date")), row.names = c(NA, 
10L), class = "data.frame")

Hi there,

It would be nice of you if you gave a short repex (reproducible example), this will speed up the feedback you'll get.
Nevertheless, from what I see, I assume you are using the shinydashboard package and the box function.
This function has a parameter width which you can use to control the width of the boxed plot and its default value is 6, meaning half of the space (see ?box). Use width=12 so that the plot takes the full width available. Same things can be done with the inputs. Or you can also add additional column elements.

Here is a small repex showing the solution:

library(shiny)
library(shinydashboard)

ui <- dashboardPage(
    dashboardHeader(),
    dashboardSidebar(),
    dashboardBody(    fluidRow( 
        column(8, box(plotOutput("regiao_plot"), width=12)), 
        column(4, 
               box(sliderInput("bin", "Number of bins:", value = 50, min = 10, max = 100), width=12),
               column(12, box(selectizeInput("regiao", "Por RegiĆ£o ou Estado:", 
                                          choices = list("Estado" = "uf", "RegiĆ£o" = "regiao"),
                                          selected = "Estado",
                                          options = list(placeholder = 'Estado')))),
               column(12, box(selectizeInput("estab", "Por tipo de Estabelecimento:", 
                           choices = list("Todos" = 3, "Matriz" = 1, "Filial" = 2),
                           selected = "Todos", 
                           options = list(placeholder = 'Todos'))))
               )
        )
    )
)

# Define server logic required to draw a histogram
server <- function(input, output) {

    output$regiao_plot <- renderPlot({
        # generate bins based on input$bins from ui.R
        x    <- faithful[, 2]
        bins <- seq(min(x), max(x), length.out = input$bin + 1)
        
        # draw the histogram with the specified number of bins
        hist(x, breaks = bins, col = 'darkgray', border = 'white')
    })
}

# Run the application 
shinyApp(ui = ui, server = server)
1 Like

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.