Change Color of sliderInput's slider bar?

1,547 views
Skip to first unread message

Sam Finlayson

unread,
May 17, 2013, 12:12:33 AM5/17/13
to shiny-...@googlegroups.com
Hey There,

Is there any way to change the color of the slider bar?  Or along those same lines, any way to see/adjust the HTML that is associated with ui.R?

Sorry if this question has already been answered.  I am just getting started (excitedly!) with shiny, and I am hopeful that the solution to this question will either a) be super simple, or b) open up a new world of how shiny development works.

Thanks so much in advance for any help!
Sam

Ramnath Vaidyanathan

unread,
May 17, 2013, 1:09:22 AM5/17/13
to shiny-...@googlegroups.com
You can use CSS to change the color.


Ramnath

Joe Cheng

unread,
May 17, 2013, 3:34:49 AM5/17/13
to shiny-...@googlegroups.com
Regarding seeing/adjusting the HTML, the easiest way is to just View Source in your web browser.

Another way is to take any subexpression in ui.R, and call cat(as.character(...)) on it. For example,
  cat(as.character(textInput("foo", "Foo")))
prints out
  <label for="foo">Foo</label>
  <input id="foo" type="text" value=""/>

The functions called in shinyUI are just list-generating code; they return data structures that represent HTML and can be manipulated. See the ?tagList, ?tags, and ?HTML help topics. Here's one example:



--
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.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Sam Finlayson

unread,
May 18, 2013, 5:00:59 PM5/18/13
to shiny-...@googlegroups.com
Thank you so much!  Very helpful!

Sam Finlayson

unread,
May 18, 2013, 5:03:59 PM5/18/13
to shiny-...@googlegroups.com
Thank you very much for the prompt reply.  So sorry if I missed something, but is there an example somewhere of how to use CSS with Shiny (i.e. how to name, where to place the file, etc.)?  Sorry for the level zero questions!

Joe Cheng

unread,
May 21, 2013, 1:51:38 AM5/21/13
to shiny-...@googlegroups.com
You can create a subdirectory "www" under your application directory, and place a .css file there. Then reference it from your ui.R. For example,

~/myapp/ui.R
~/myapp/server.R
~/myapp/www/styles.css

In your ui.R you can put a tags$link anywhere, for example in mainPanel:

mainPanel(
  tags$link(rel="stylesheet", type="text/css", href="styles.css"),
  # more controls go here...
)

That tags$link will become:
<link rel="stylesheet" type="text/css" href="styles.css"/>

Notice that while your styles.css is stored in a www directory, you do not reference "www" in your link tag.


--

Sam Finlayson

unread,
May 21, 2013, 1:58:52 AM5/21/13
to shiny-...@googlegroups.com
Thank you so much!  Very much appreciated.

Andrew Clark

unread,
Jun 5, 2013, 2:01:11 PM6/5/13
to shiny-...@googlegroups.com
Is it possible to move the www/styles.css to the root directory so that it can service several apps
I tried this with href="./styles.css" and href="./www/styles.css" but does not seem to  work with either

Joe Cheng

unread,
Jun 6, 2013, 3:46:36 AM6/6/13
to shiny-...@googlegroups.com
You might take a look at addResourcePath, it can be used to map an arbitrary directory on disk to a URL for serving up static assets. You'll have to call it from each app though.

Andrew Clark

unread,
Jun 6, 2013, 6:15:08 PM6/6/13
to shiny-...@googlegroups.com
Had a quick look but haven't fathomed out yet
I cannot do something like
 tags$head(
         tags$link(rel = 'stylesheet', type = 'text/css', href = 'styles.css'),
         tags$link(rel = 'stylesheet', type = 'text/css', href = 'appStyles.css'),
    )

where appStyles would be CSS specific to the app?
The above code does not cause an error - but doesnt work either

Ramnath Vaidyanathan

unread,
Jun 6, 2013, 8:12:19 PM6/6/13
to shiny-...@googlegroups.com
Here is one way to do what Joe suggested. Suppose all your common css files are in a folder named 'common', and the absolute path to it is given by path_to_common. 

addResourcePath('common', path_to_common)
tags$head(
         tags$link(rel = 'stylesheet', type = 'text/css', href = 'common/styles.css'),
         tags$link(rel = 'stylesheet', type = 'text/css', href = 'common/appStyles.css'),
)

The first line tells Shiny to map all assets starting with the prefix "common" to the full path.

Hope this helps.
Reply all
Reply to author
Forward
0 new messages