File: ui.R

package info (click to toggle)
r-cran-formatr 1.4-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 232 kB
  • sloc: sh: 10; makefile: 4
file content (41 lines) | stat: -rw-r--r-- 1,716 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
library(shiny)

shinyUI(fluidPage(
  title = 'Tidy R Code with formatR (Yihui Xie)',
  helpText(),  # just a placeholder for a little bit top margin
  sidebarLayout(
    sidebarPanel(
      tags$head(
        tags$script(src = 'shiny-handler.js'),
        tags$style(type = 'text/css', '.popover {max-width: 100%;}')
      ),
      helpText('This Shiny app uses the function', code('tidy_source()'),
               'in the', a(href = 'http://yihui.name/formatR', strong('formatR')),
               sprintf('(>= v%s)', packageVersion('formatR')),
               'package to reformat R code in the text box on the right.',
               a(list(icon('hand-o-right'), 'demo'), class = 'btn btn-small btn-info',
                 onclick = '$("textarea#src").val($("#demo").val()).trigger("change");')),
      checkboxInput('arg_comment', 'Preserve comments', TRUE),
      checkboxInput('arg_blank', 'Preserve blank lines', TRUE),
      checkboxInput('arg_assign', 'Replace = with <-', FALSE),
      checkboxInput('arg_brace', 'Put { on a new line', FALSE),
      numericInput ('arg_indent', 'Number of spaces for indentation', 4, min = 0),
      numericInput ('arg_width', 'Minimum line width', 70, min = 20, max = 500),
      submitButton ('Tidy My Code', icon('toggle-right'))
    ),
    mainPanel(
      tags$textarea(
        id = 'src', rows = 20,
        style = 'width: 99%; font-family: monospace; word-wrap: normal; white-space: pre;',
        placeholder = 'paste your R code here...'
      ),
      tags$textarea(
        id = 'demo', style = 'display: none;',
        paste(
          readLines(system.file('format', 'messy.R', package = 'formatR')),
          collapse = '\n'
        )
      )
    )
  )
))