diff --git a/NAMESPACE b/NAMESPACE index 4681cf71f..718b5ec31 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,10 +1,12 @@ export(appendChild) export(br) +export(checkboxInput) export(clientPage) export(div) export(h1) export(h2) export(header) +export(hr) export(img) export(input) export(inputs) @@ -19,10 +21,11 @@ export(reactiveTimer) export(runApp) export(script) export(shinyPlot) -export(shinyText) +export(span) export(style) export(tag) export(textInput) +export(textOutput) export(withHeadTags) S3method(reactive,default) S3method(reactive,"function") diff --git a/R/ui.R b/R/ui.R index 27d9ee92a..8364d970b 100644 --- a/R/ui.R +++ b/R/ui.R @@ -76,6 +76,11 @@ div <- function(...) { tag("div", ...) } +#' @export +span <- function(...) { + tag("span", ...) +} + #' @export img <- function(...) { tag("img", ...) @@ -106,6 +111,12 @@ br <- function(...) { tag("br", ...) } +#' @export +hr <- function(...) { + tag("hr", ...) +} + + htmlEscape <- local({ .htmlSpecials <- list( `&` = '&', @@ -153,21 +164,44 @@ shinyPlot <- function(outputId) { } #' @export -shinyText <- function(outputId) { - div(id = outputId, class = "live-text") +textOutput <- function(outputId, + caption = "", + captionOnTop = FALSE) { + tag <- div() + if (nzchar(caption)) { + tag <- appendChild(tag, caption) + if (captionOnTop) + tag <- appendChild(tag, br()) + } + tag <- appendChild(tag, span(id = outputId, class = "live-text")) } - - #' @export -textInput <- function(inputId, label, value = "", labelOnTop = FALSE) { - tag <- p(label) - if (labelOnTop) +textInput <- function(inputId, + caption = "", + captionOnTop = FALSE, + initialValue = "") { + tag <- p(caption) + if (captionOnTop) tag <- appendChild(tag, br()) - tag <- appendChild(tag, input(name = inputId, type = 'text', value = value)) + tag <- appendChild(tag, input(name = inputId, type = 'text', value = initialValue)) } +#' @export +checkboxInput <- function(inputId, + caption, + initialValue = FALSE) { + tag <- p() + inputTag <- input(type="checkbox", name=inputId) + if (initialValue) + inputTag$attribs$checked <- "checked" + tag <- appendChild(tag, inputTag) + + tag <- appendChild(tag, caption) +} + + #' @export diff --git a/examples/01_allcaps/app.R b/examples/01_allcaps/app.R index 4ffabb2da..6cb1c2f20 100644 --- a/examples/01_allcaps/app.R +++ b/examples/01_allcaps/app.R @@ -2,12 +2,9 @@ library(shiny) client <- clientPage( - textInput("val", - label = "Input:", - value = "Hello, World!", - labelOnTop = TRUE), + textInput("val", caption = "Input:", initialValue = "Hello, World!"), - p("You said:"), shinyText("valUpper") + textOutput("valUpper", caption = "You said:") ) server <- function(input, output) { diff --git a/examples/02_hash/app.R b/examples/02_hash/app.R index 6828fb90e..6bb8bdcdf 100644 --- a/examples/02_hash/app.R +++ b/examples/02_hash/app.R @@ -1,7 +1,17 @@ library(shiny) library(digest) -app <- function(input, output) { +client <- clientPage( + + textInput("input1", caption="Input:", initialValue="Hello, world!"), + checkboxInput("addnewline", caption = "Append newline", initialValue=TRUE), + + textOutput("md5_hash", caption = "MD5:"), + textOutput("sha1_hash", caption = "SHA-1:") + +) + +server <- function(input, output) { text <- reactive(function() { str <- input$input1 if (input$addnewline) @@ -18,4 +28,4 @@ app <- function(input, output) { }) } -runApp(client='./www', server=app) \ No newline at end of file +runApp(client, server, port=8500) \ No newline at end of file