Created
January 12, 2014 16:10
-
-
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")
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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;}" | |
) | |
) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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;}' | |
) | |
) | |
}" | |
) | |
}) | |
} | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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