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