Search code examples
rshinyecharts4r

how I can align to the left on shiny?


Hi and thanks for reading me

I am working on a shiny bar chart and I would like it to display from the left without a space in between, that is, I would like to remove the following space and for the chart to start from there:

enter image description here

Is there a way to do that? My code is the following:

library(shiny)
library(dplyr)
library(echarts4r)

shinyApp(
  ui = fixedPage(
    column(12, align="center", offset = 0,
           echarts4rOutput(
             "grafico", width = 1500, height = 350
           )
    )
    
  ),
  server = function(input, output){
    
    
    output$grafico <- renderEcharts4r({
      mtcars |>
        tibble::rownames_to_column("model") |> 
        mutate(total = mpg + qsec) |>
        arrange(desc(total)) |>
        e_charts(model) |>
        e_bar(mpg, stack = "grp") |>
        e_bar(qsec, stack = "grp")
      
    })
    
  }
)

Solution

  • This is kind of an ugly fix, but it works: (mind you, I changed the fixedPage to a fluidPage. I also added a div to encapsulate your echarts4rOutput)

    library(shiny)
    library(dplyr)
    library(echarts4r)
    
    shinyApp(
      ui = fluidPage(
        fluidRow(
          column(
            12,
            tags$div(
              style = "margin-left: -75px", offset = 0,
              echarts4rOutput(
                "grafico", width = 1080, height = 350
              )
            )
          )
        )
      ),
      server = function(input, output){
    
    
    output$grafico <- renderEcharts4r({
      mtcars |>
        tibble::rownames_to_column("model") |> 
        mutate(total = mpg + qsec) |>
        arrange(desc(total)) |>
        e_charts(model) |>
        e_bar(mpg, stack = "grp") |>
        e_bar(qsec, stack = "grp")
      
    })
    
    
    
     }
    )