Horizontally align widgets

2,667 views
Skip to first unread message

charlot...@gmail.com

unread,
Feb 17, 2015, 9:49:21 AM2/17/15
to shiny-...@googlegroups.com
Hi everyone,

I am trying to center a widget (a sliderInput) under a plot in order to align the xlim of the xaxis of the plot with the min and max of the sliderInput.
I didn't manage to find an option to horizontally align widgets.
First, is it possible ? and if so, how ?

Thank you very much in advance for your help

Cha

My simplified code :

runApp(list(
  ui = fluidPage(
   
    # Application title
    titlePanel("Hello Shiny!"),
   
    # Sidebar with a slider input for the number of bins
    sidebarLayout(
      sidebarPanel(width = 2
                  
      ),
     
      # Show a plot of the generated distribution
      mainPanel(
        fluidRow(
          column(6,
                 plotOutput("distPlot"),
                 sliderInput("bins",
                             "Number of bins:",
                             min = 1,
                             max = 50,
                             value = 30, width = 500)
                
          ),
          column(6
          )
        )
       
      )
    )
  ),
  server = function(input, output) {
   
    output$distPlot <- renderPlot({
      plot(1,1)
    })
  }
 
  ))

Joe Cheng

unread,
Feb 18, 2015, 3:34:47 PM2/18/15
to charlot...@gmail.com, shiny-...@googlegroups.com
It's a little trickier for sliderInput than for other things, try adding this function before defining UI:

alignCenter <- function(el) {
  htmltools::tagAppendAttributes(el,
    style="margin-left:auto;margin-right:auto;"
  )
}

Then surround the sliderInput with alignCenter(...).

--
You received this message because you are subscribed to the Google Groups "Shiny - Web Framework for R" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/shiny-discuss/98dd2700-3599-429d-99a5-af13eef32c1c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

charlot...@gmail.com

unread,
Feb 23, 2015, 5:05:29 AM2/23/15
to shiny-...@googlegroups.com
Nice !!
Thank you very much Joe !!
Have a nice day !

Cha

charlot...@gmail.com

unread,
Feb 26, 2015, 8:55:29 AM2/26/15
to shiny-...@googlegroups.com
Hi Joe !

After trying your function, it seems that it doesn't work in my case !!

Did I misunderstood your advice ? Is the function in the right place ?

Below, my code with alignCenter :

alignCenter <- function(el) {
  htmltools::tagAppendAttributes(el,
                                 style="margin-left:auto;margin-right:auto;"
  )
}

runApp(list(
  ui = fluidPage(
   
    # Application title
    titlePanel("Hello Shiny!"),
   
    # Sidebar with a slider input for the number of bins
    sidebarLayout(
      sidebarPanel(width = 2
                  
      ),
     
      # Show a plot of the generated distribution
      mainPanel(
        fluidRow(
          column(6,
                 plotOutput("distPlot"),
                 alignCenter(sliderInput("bins",

                             "Number of bins:",
                             min = 1,
                             max = 50,
                             value = 30, width = 500))
                
          ),
          column(6
          )
        )
       
      )
    )
  ),
  server = function(input, output) {
   
    output$distPlot <- renderPlot({
      plot(1,1)
    })
  }
 
))


Again thank you very much for your help

Cha

Le mardi 17 février 2015 15:49:21 UTC+1, charlot...@gmail.com a écrit :

Joe Cheng

unread,
Feb 26, 2015, 10:56:56 AM2/26/15
to charlot...@gmail.com, shiny-...@googlegroups.com

That would center it just within the 6-wide column you have in your mainPanel, is that what you want?

--
You received this message because you are subscribed to the Google Groups "Shiny - Web Framework for R" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discus...@googlegroups.com.
Message has been deleted

charlot...@gmail.com

unread,
Feb 26, 2015, 11:53:02 AM2/26/15
to shiny-...@googlegroups.com
Yes ! It is exactly what I want. Does it work for you ?

Reply all
Reply to author
Forward
0 new messages