Debian Codegraph @

inst/sass-color/app.R

raw
1 library(shiny)
2 library(sass)
3 library(colourpicker)
4
5 ui <- fluidPage(
6 headerPanel("Sass Color Example"),
7 uiOutput("sass"),
8
9 sidebarPanel(
10 colourInput("color", "Background Color", value = "#6498d2",
11 showColour = "text")
12 ),
13
14 mainPanel(
15 plotOutput("distPlot"),
16 br()
17 ),
18
19 column(6, verbatimTextOutput("scssTxt")),
20 column(6, verbatimTextOutput("cssTxt"))
21 )
22
23 server <- function(input, output) {
24 output$distPlot <- renderPlot({
25 hist(rnorm(500))
26 })
27
28 variables <- reactive({
29 list(
30 color = input$color
31 )
32 })
33
34 sass_input <- reactive({
35 list(
36 variables(),
37 paste(
38 "body {",
39 " background-color: $color;",
40 "}",
41 sep = "\n"
42 )
43 )
44 })
45 compiled_css <- reactive({
46 sass(sass_input())
47 })
48
49 output$sass <- renderUI({
50 tags$head(tags$style(compiled_css()))
51 })
52
53 output$scssTxt <- renderText({
54 paste0("/* Sass */\n", as_sass(sass_input()))
55 })
56
57 output$cssTxt <- renderText({
58 paste0("/* Compiled CSS */\n", compiled_css())
59 })
60 }
61
62 shinyApp(ui, server)