Skip to content

Instantly share code, notes, and snippets.

@ptoche
Created January 12, 2014 16:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ptoche/8386571 to your computer and use it in GitHub Desktop.
Save ptoche/8386571 to your computer and use it in GitHub Desktop.
Demo on 'source' tags$style from global.R, alternative to includeCSS("www/style.css")
# global.R
# customize display settings here
gTags <- function() {
tags$head(
tags$style(
type = 'text/css'
, "body {font-size: 80%; color: rgb(0,0,100);}"
, "#mainPanelId {min-width: 50%; max-width: 70%; float: right;}"
, "#sidebarPanelId {min-width: 10%; max-width: 20%; float: left;}"
, "h1 {font-size: 20px; color: orange;}"
)
)
}
# server.R
library("shiny")
shinyServer(
function(input, output, session) {
# Display styles
output$main <- renderText({
paste0(
" gTags <- function() {
tags$head(
tags$style(
type = 'text/css'
, 'body {font-size: 80%; color: rgb(0,0,100);}'
, '#mainPanelId {min-width: 50%; max-width: 70%; float: right;}'
, '#sidebarPanelId {min-width: 10%; max-width: 20%; float: left;}'
, 'h1 {font-size: 20px; color: orange;}'
)
)
}"
)
})
}
)
# ui.R
library("shiny")
shinyUI(
pageWithSidebar(
# Panel 1
headerPanel("Passing Tags - Demo")
,
# Panel 2
sidebarPanel = wellPanel(
id = "sidebarPanelId"
,
h4("Not Much Here")
,
helpText("This is a very minimal demo designed to illustrate how styles can be stored in 'global.R'
and how they may be passed to 'ui.R'.
Other than that it appears to work, I do not know if it's a commendable approach.
As for the layout of the panels, it's lousy but, again, just an illustration.
Oh and the code you see in the mainPanel, it's not even sourced, it's copy-pasted from 'global.R'.")
)
,
# Panel 3
mainPanel = wellPanel(
id = "mainPanelId"
,
# pass customized display settings stored in function gTags() in global.R
gTags()
,
tableOutput(outputId = "table")
,
h4("Store your css styles in 'global.R' :")
,
verbatimTextOutput("main")
)
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment