Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben Moore committed Jun 22, 2017
0 parents commit d246a53
Show file tree
Hide file tree
Showing 4 changed files with 188 additions and 0 deletions.
92 changes: 92 additions & 0 deletions server.R
@@ -0,0 +1,92 @@

# This is the server logic for a Shiny web application.
# You can find out more about building applications with Shiny here:
#
# http://shiny.rstudio.com
#

library(ggplot2)
library(shiny)
library(mandelbrot)

cols <- c(
colorRampPalette(c("#e7f0fa", "#c9e2f6", "#95cbee",
"#0099dc", "#4ab04a", "#ffd73e"))(10),
colorRampPalette(c("#eec73a", "#e29421", "#e29421",
"#f05336","#ce472e"), bias=2)(90),
"black")

shinyServer(function(input, output) {

limits <- reactiveValues(xlim = NULL, ylim = NULL)

cols <- reactiveValues(cols = cols)

output$mandelbrot <- renderPlot({

if (!is.null(limits$xlim)) {
df <- as.data.frame(
mandelbrot(
iterations = input$iter,
resolution = input$res,
xlim = limits$xlim,
ylim = limits$ylim
)
)
} else {
df <- as.data.frame(
mandelbrot(
iterations = input$iter,
resolution = input$res
)
)
}

ggplot(df, aes(x = x, y = y, fill = value)) +
geom_raster(interpolate = TRUE) + theme_void() +
scale_fill_gradientn(colours = cols$cols, guide = "none") +
coord_equal()

})

observe({
brush <- input$zoom_brush

if (!is.null(brush)) {
limits$xlim <- c(brush$xmin, brush$xmax)
limits$ylim <- c(brush$ymin, brush$ymax)
}

})

observe({
pal <- input$palette

if (pal == "Spectral") {
cols$cols <- mandelbrot_palette(RColorBrewer::brewer.pal(11, "Spectral"))
}

if (pal == "Vaccine") {
cols$cols <- c(
colorRampPalette(c("#e7f0fa", "#c9e2f6", "#95cbee",
"#0099dc", "#4ab04a", "#ffd73e"))(10),
colorRampPalette(c("#eec73a", "#e29421", "#e29421",
"#f05336","#ce472e"), bias=2)(90),
"black")
}

if (pal == "Greyscale") {
cols$cols <- mandelbrot_palette(grey.colors(50))
}

if (pal == "Heat") {
cols$cols <- mandelbrot_palette(heat.colors(50))
}

if (pal == "Ice") {
cols$cols <- mandelbrot_palette(RColorBrewer::brewer.pal(9, "Blues"), in_set = "white")
}

})

})
13 changes: 13 additions & 0 deletions shinybrot.Rproj
@@ -0,0 +1,13 @@
Version: 1.0

RestoreWorkspace: Default
SaveWorkspace: Default
AlwaysSaveHistory: Default

EnableCodeIndexing: Yes
UseSpacesForTab: Yes
NumSpacesForTab: 2
Encoding: UTF-8

RnwWeave: knitr
LaTeX: pdfLaTeX
53 changes: 53 additions & 0 deletions ui.R
@@ -0,0 +1,53 @@

# This is the user-interface definition of a Shiny web application.
# You can find out more about building applications with Shiny here:
#
# http://shiny.rstudio.com
#

library(shiny)

shinyUI(navbarPage("Mandelbrot", id="nav", collapsible=T,
tabPanel("View",
div(class = "outer",
tags$head(
includeCSS("www/styles.css")
),

plotOutput("mandelbrot", height = "800px", width = "1000px",
brush = brushOpts(id = "zoom_brush", resetOnNew = TRUE, delay = 600)),

absolutePanel(
id = "controls", class = "panel panel-default", fixed = TRUE,
draggable = TRUE, top = 100, left = 20, right = "auto", bottom = "auto",
width = 400, height = "auto",

# panel content
h2("Controls"),

sliderInput("iter",
"Iterations:",
min = 100,
max = 1000,
value = 300,
step = 50,
width = "98%"),

sliderInput("res",
"Resolution:",
min = 100,
max = 2000,
value = 500,
step = 100,
width = "98%"),

radioButtons("palette",
"Colours:",
choices = c("Vaccine", "Spectral", "Greyscale", "Heat", "Ice"),
width = "98%",
inline = TRUE)

)
)
)
))
30 changes: 30 additions & 0 deletions www/styles.css
@@ -0,0 +1,30 @@
div#mandelbrot {
margin: 0 auto;
}

div.outer {
position: fixed;
top: 41px;
left: 0;
right: 0;
bottom: 0;
overflow: hidden;
padding: 0;
}


#controls {
background-color: white;
padding: 0 20px 0px 20px;
cursor: move;
/* Fade out while not hovering */
opacity: 0.7;
transition: opacity 500ms 1s;
font-size: smaller;
}

#controls:hover {
/* Fade in while hovering */
opacity: 1;
transition-delay: 0;
}

0 comments on commit d246a53

Please sign in to comment.