thorn-shiny {thorn}R Documentation

Shiny bindings for thorn

Description

Output and render functions for using thorn within Shiny applications and interactive Rmd documents.

Usage

thornOutput(outputId, width = "100%", height = "100%")

renderThorn(expr, env = parent.frame(), quoted = FALSE)

Arguments

outputId

output variable to read from

width, height

a valid CSS measurement (like "100%", "400px", "auto") or a number, which will be coerced to a string and have "px" appended

expr

an expression that generates a shader created with thorn

env

the environment in which to evaluate expr

quoted

logical, whether expr is a quoted expression

Examples

# use a shader as the background of a Shiny app ####
library(thorn)
library(shiny)

ui <- fluidPage(
  thornOutput("thorn", width = "100%", height = "100%"),
  br(),
  sidebarLayout(
    sidebarPanel(
      sliderInput(
        "slider", "Slide me",
        value = 10, min = 0, max = 20
      ),
      selectInput(
        "select", "Select me", choices = c("Choice 1", "Choice 2")
      )
    ),
    mainPanel()
  )
)

server <- function(input, output){

  output[["thorn"]] <- renderThorn({
    thorn("biomorph2")
  })

}

if(interactive()){
  shinyApp(ui, server)
}

# all available shaders ####
library(thorn)
library(shiny)

ui <- fluidPage(
  br(),
  sidebarLayout(
    sidebarPanel(
      wellPanel(
        radioButtons(
          "shader", "Shader",
          choices = c(
            "thorn",
            "thorn-color",
            "ikeda",
            "biomorph1",
            "biomorph2",
            "biomorph3",
            "sweet",
            "apollony",
            "smoke"
          )
        )
      )
    ),
    mainPanel(
      thornOutput("shader", width = "calc(100% - 15px)", height = "400px")
    )
  )
)

server <- function(input, output){

  output[["shader"]] <- renderThorn({
    thorn(input[["shader"]])
  })

}

if(interactive()){
  shinyApp(ui, server)
}

[Package thorn version 0.2.0 Index]