Compare commits

...

1520 Commits

Author SHA1 Message Date
Joe Cheng
e9fc873c8d Restore HTML generating functions
These functions were temporarily ripped out of Shiny and moved
to the htmltools package. We've discovered that it's safe to
keep including them in shiny; as long as the functions in shiny
and the functions in htmltools are identical, the user won't
receive a conflict warning.
2014-05-29 14:00:48 -07:00
Joe Cheng
0153349979 Make S3 method consistent with base 2014-05-28 13:28:02 -07:00
Joe Cheng
d227842414 Update htmltools version 2014-05-28 13:20:54 -07:00
Joe Cheng
b6a2122a41 Merge remote-tracking branch 'origin/master' into htmltools-refactor
Conflicts:
	R/shiny.R
	man/session.Rd
2014-05-28 13:18:49 -07:00
Joe Cheng
a0df8f3490 Merge pull request #491 from rstudio/bugfix/validation-silent
Suppress validation errors from printing at console
2014-05-28 13:14:02 -07:00
Winston Chang
6c14789362 Merge pull request #492 from rstudio/bugfix/0.10misc
Miscellaneous bug fixes
2014-05-23 14:13:29 -05:00
Winston Chang
880a12b914 Merge pull request #489 from yihui/bugfix/428
Fixes #428
2014-05-23 14:09:43 -05:00
Joe Cheng
93d69400e6 Merge pull request #486 from yihui/feature/widget-width
Width of selectize and sliders
2014-05-22 15:43:34 -07:00
Joe Cheng
d4829e49ea Doc tweak to validation 2014-05-21 19:57:18 -07:00
Joe Cheng
1c56be3a6b Suppress validation errors from printing at console 2014-05-21 19:51:24 -07:00
Joe Cheng
07a0dfddc7 Validation error causes real errors to look like validation errors
The CSS class for validation errors was not being properly removed between different kinds of errors
2014-05-21 19:32:44 -07:00
Joe Cheng
b86f9086ef Avoid black background when renderPlot doesn't actually plot 2014-05-21 19:28:51 -07:00
Joe Cheng
343ca12c6f Don't print NULL to the console during renderPrint 2014-05-21 19:28:28 -07:00
Joe Cheng
af3c4f84b6 Merge pull request #488 from yihui/bugfix/220
fix #220: the first entry in zip is not necessarily a directory
2014-05-20 00:32:11 -07:00
Yihui Xie
3679e8795f fix #220: the first entry is not necessarily a directory
in that case, we use dirname() on the first entry
2014-05-20 01:43:48 -05:00
Yihui Xie
39b4805a76 make sure the selected argument never contains names; fixes #428 2014-05-20 01:31:14 -05:00
Yihui Xie
3bdcdf96d4 upgrade selectize.js to v0.9.1 to fix the third issue in #428 2014-05-20 01:30:37 -05:00
Yihui Xie
b54e5d33bc roxygenize 2014-05-19 11:25:40 -05:00
Yihui Xie
85e020a513 examples of the 'width' argument 2014-05-19 11:24:56 -05:00
Yihui Xie
5b6268f5bc add width to selectInput() as well 2014-05-19 11:23:52 -05:00
Yihui Xie
f8b38e4683 validateCssUnit(width) for selectize and slider 2014-05-17 01:32:01 -05:00
Yihui Xie
18e85c32b4 roxygenize 2014-05-17 01:28:27 -05:00
Yihui Xie
831fba9a53 add a 'width' option to selectizeInput() and sliderInput() to specify the width of these widgets 2014-05-17 01:28:27 -05:00
Joe Cheng
b1f233cd8c Merge remote-tracking branch 'origin/pr/485'
Conflicts:
	NEWS
2014-05-16 23:22:01 -07:00
Yihui Xie
3d0caba695 \emph cannot be used in \code{}: only \var and \link are allowed 2014-05-17 00:53:57 -05:00
Yihui Xie
79c92f1f8e fixes #429, which is yet yet another WAT of RJSONIO
perhaps we really should consider switching to jsonlite...
2014-05-17 00:43:13 -05:00
Joe Cheng
78f87d9003 Dependency fixes
1) Give bootstrap deps a path so they can be used in static docs
2) Resolve dependencies before rendering page (whoops)
2014-05-16 15:39:08 -07:00
Yihui Xie
87f26e47bb a news item for the 'width' argument of renderPrint() 2014-05-16 14:19:55 -05:00
Yihui Xie
9d8d04ae28 add a 'width' argument so we can control the width of the text output 2014-05-16 14:17:50 -05:00
Yihui Xie
a42f046ff8 capture.output() has already considered withVisible(), and we do not need to redo it 2014-05-16 14:12:50 -05:00
Joe Cheng
0824726dbb Adapt to htmltools 0.2.1 API 2014-05-15 15:17:42 -07:00
Joe Cheng
f55155404a Remove obsolete entry from staticdocs index 2014-05-14 17:13:38 -07:00
Joe Cheng
b711bb553f Add S3 method for turning render function into tags 2014-05-14 17:12:15 -07:00
Joe Cheng
2a36179bdc Fix broken client-side HTML dependency rendering 2014-05-14 17:12:15 -07:00
Joe Cheng
e57221861f Extract HTML functionality to htmltools library 2014-05-14 17:12:15 -07:00
Joe Cheng
b00fbda1ae Make sure random bytes are formatted with 2 chars 2014-05-14 17:11:18 -07:00
Joe Cheng
357e81aeca Bump version 2014-05-14 09:14:19 -07:00
Joe Cheng
3189c748b5 Merge pull request #479 from rstudio/not-just-last-expressions
Allow shinyUI and shinyServer calls to not be the last expression in ui....
2014-05-14 09:06:28 -07:00
Joe Cheng
2700643cbf Merge pull request #480 from jcheng5/bugfix/renderplot-height-overlap
Fix #477: renderPlot in shinydoc with height > 400 overlaps subsequent c...
2014-05-14 09:06:15 -07:00
Winston Chang
ff628ac0b2 Fixes for jshint 2014-05-12 20:46:24 -05:00
Joe Cheng
f21aefe9e9 Merge pull request #467 from yihui/cosmetic
Some cosmetic changes regarding NULL
2014-05-10 02:13:25 -07:00
Joe Cheng
8babbd69d8 Merge branch 'session-documentation'
Conflicts:
	inst/staticdocs/index.r
2014-05-09 19:41:19 -07:00
Joe Cheng
11bf02eb56 Merge pull request #478 from rstudio/remove-literate-programming
Stop using literate programming
2014-05-09 19:39:58 -07:00
Joe Cheng
f5fa7d6d4b Fix #477: renderPlot in shinydoc with height > 400 overlaps subsequent content 2014-05-09 18:14:28 -07:00
Joe Cheng
77bff6e6c2 Allow shinyUI and shinyServer calls to not be the last expression in ui.R and server.R 2014-05-08 16:14:53 -07:00
Joe Cheng
e84a76cebd Merge pull request #457 from yihui/feature/unsatisfied-input
A first attempt of the custom error type for unsatisfied input dependencies
2014-05-08 16:12:58 -07:00
Yihui Xie
342265be94 put the custom class(es) in the first as Hadley suggested 2014-05-08 15:04:49 -07:00
Yihui Xie
62ec9291d8 Merge pull request #1 from jcheng5/feature/unsatisfied-input
Refactoring/renaming of validation
2014-05-08 14:57:54 -07:00
Joe Cheng
dee6fbcb8f Stop using literate programming
Couldn't build from source without knitr installed, and knitr
is not a required dependency
2014-05-08 14:54:11 -07:00
JJ Allaire
72fa9a2dcb bump version 2014-05-08 12:54:20 -04:00
Joe Cheng
ca27a9e31a Validation refactoring
- Move validation logic from shinywrappers.R to utils.R
- Don't coerce validation results; fail if not FALSE, NULL, or character
- Reverse order of stopWithCondition args
2014-05-07 16:20:07 -07:00
Joe Cheng
18d0f45cf9 Refactoring/renaming of validation
- validateInput renamed to validate
- validateCondition renamed to need
- Removed ability to provide "bare" conditions. It is
  still possible to fail validation silently by passing
  FALSE as the second argument to need()
- Rather than using a two-element list to convey results,
  use a single result protocol; NULL is success, FALSE is
  silent failure, string is failure with message
- Tweak "missing input" semantics, add tests
2014-05-07 16:09:06 -07:00
Joe Cheng
424fd515a4 Merge pull request #472 from rstudio/bugfix/delayed-assign-2
Remove delayedAssign which causes problems for downstream packages
2014-05-07 09:56:19 -07:00
Joe Cheng
00b40d64a1 Remove delayedAssign which causes problems for downstream packages
See comment on d7eb9b2d18
2014-05-06 20:40:57 -07:00
Joe Cheng
3a7d0a5a9f Document session object
Also allow http handlers to return standard Rook responses instead of
httpResponse objects.
2014-05-06 11:56:23 -07:00
Joe Cheng
57a02318e3 Clearer error message when shinyAppDir is given a nonexistent path 2014-05-05 15:31:21 -07:00
Joe Cheng
8f6d8cf0d6 Slider with label=NULL doesn't have tag classes attached 2014-05-05 14:00:43 -07:00
Joe Cheng
5b6605b296 Add inputPanel to staticdocs index 2014-05-05 13:59:46 -07:00
Joe Cheng
4d83596595 Merge pull request #465 from rstudio/feature/horizontal-layout
New layouts for horizontal placement
2014-05-05 13:10:26 -07:00
Joe Cheng
7e12a281f5 Remove slider from bundled jquery-ui 2014-05-05 12:12:41 -07:00
Joe Cheng
c63c10e48a Merge pull request #466 from rstudio/bugfix/space-urls
Encode pathname when necessary on browsers that supply it decoded
2014-05-05 11:40:06 -07:00
Joe Cheng
155554f0b7 Only double-encode on Qt 2014-05-05 11:36:27 -07:00
Yihui Xie
26b0836756 since NULL in tag() will be dropped, there is no need to check is.null(icon) 2014-05-03 01:11:32 -05:00
Yihui Xie
a87dc9bab2 cosmetic: both if (FALSE) expr and for-loops return NULL 2014-05-03 01:09:51 -05:00
Yihui Xie
9c1555a110 tweak an RStudio project option 2014-05-03 00:54:44 -05:00
Joe Cheng
fbda2db884 Only show special "No UI defined" message for shinyAppDir 2014-05-02 18:52:37 -07:00
Joe Cheng
2a229774ef Merge pull request #463 from jcheng5/bugfix/faster-select
Massively faster selectInput
2014-05-02 17:31:38 -07:00
Joe Cheng
137e5b13ef Update tests 2014-05-02 17:28:01 -07:00
Joe Cheng
7920d66cd0 Separate option tags with newline 2014-05-02 17:26:27 -07:00
Yihui Xie
9f2dae7f3b the logic of the last commit was not correct: we should not stop immediately on a non-condition object; instead, we still need to collect all messages on all conditions before we stop 2014-05-02 18:13:35 -05:00
Yihui Xie
ffde0ad1f5 roxygenize 2014-05-02 17:56:20 -05:00
Yihui Xie
2c2658a8ec rewrite the lapply()/vapply() with a plain dumb for-loop 2014-05-02 17:54:05 -05:00
Yihui Xie
6f2f8f6f7a add a function validateCondition() to avoid ambiguity
two advantages:

1. we no longer need to worry about input$foo being a list;
2. users have to explicitly call validateCondition() when they want error messages, so we know when to silently stop;
2014-05-02 17:33:29 -05:00
Yihui Xie
4b6dcdd1b0 use shiny-output-error as the _prefix_ for CSS classes of error messages 2014-05-02 16:56:43 -05:00
Yihui Xie
de346fd6c3 filter out some common error classes 2014-05-02 16:56:43 -05:00
Yihui Xie
bf9d7c2012 use the classes of the error condition as names of CSS classes in the output 2014-05-02 16:56:43 -05:00
Yihui Xie
143803f86d factor out stop() code to a separate function 2014-05-02 16:56:43 -05:00
Yihui Xie
311143451d condition first, message second 2014-05-02 16:56:43 -05:00
Jonathan McPherson
c9030f401d encode pathname when necessary on browsers that supply it decoded 2014-05-02 14:41:11 -07:00
Joe Cheng
8668ddce74 Tweak padding 2014-05-02 12:21:34 -07:00
Joe Cheng
7a495357f7 Update NEWS, tweak description for flowLayout 2014-05-02 12:06:15 -07:00
Joe Cheng
13864a811d Add inputPanel 2014-05-02 12:06:15 -07:00
Joe Cheng
5b65e4b250 Replace horizontalLayout with flowLayout; add splitLayout 2014-05-02 12:06:15 -07:00
Joe Cheng
dfe4a80501 Update NEWS 2014-05-02 12:06:15 -07:00
Joe Cheng
bf82b9742a Use standardized widths for selectize/jslider
The 100% width worked well inside of a sidebar, but in other situations
like full-width columns or zero-min-width tables a fixed width is better.
If there's demand we can add parameters for setting the width to custom
values including 100%.
2014-05-02 12:06:14 -07:00
Joe Cheng
829a466f72 New horizontalLayout function; put elements in a single table row 2014-05-02 12:06:14 -07:00
Yihui Xie
1206c70c42 we -> you 2014-05-02 12:45:35 -05:00
Joe Cheng
3c32c349b9 Always use Rscript from R_HOME 2014-05-02 09:12:28 -07:00
Yihui Xie
0709f08d65 a custom type of errors for unsatisfied input dependencies 2014-05-01 18:13:56 -05:00
Joe Cheng
50f78c6e40 Make tabsetPanel result visible
Without this, they don't show up in knitr documents
2014-05-01 14:31:25 -07:00
Joe Cheng
7e7afc6d38 Massively faster selectInput 2014-05-01 14:16:27 -07:00
Winston Chang
1130eadac8 Bump version 2014-04-30 14:35:08 -05:00
Winston Chang
959fc2bbb2 Merge pull request #459 from jcheng5/naked-render-in-tags
Allow naked renderXXX functions to be used inside other tags
2014-04-30 13:24:38 -05:00
Joe Cheng
f8ae505011 Change all "is()" calls to "inherits()"
According to ?inherits
2014-04-30 11:19:49 -07:00
Joe Cheng
cd183a1926 Merge branch 'feature/mask-reactive-context'
Conflicts:
	NEWS
2014-04-30 11:14:50 -07:00
Joe Cheng
bb2796fbc3 Add tests 2014-04-30 11:14:20 -07:00
Joe Cheng
5de7103890 Upgrade jqueryui to 1.10.4 and remove datepicker
The jqueryui datepicker collides with our bootstrap datepicker

Reviewed by @wch
2014-04-30 11:07:51 -07:00
Joe Cheng
a78c91ba7e Make renderPlot print result if visible
Reviewed by @wch
2014-04-30 10:10:06 -07:00
Joe Cheng
fca50da57b Fix staticdoc test 2014-04-29 12:09:37 -07:00
Joe Cheng
61f2c908b1 Add maskReactiveContext function 2014-04-29 12:01:03 -07:00
Joe Cheng
4c096ac068 Merge pull request #454 from yihui/feature/selectize-more
Make `selected` work for server-side selectize input
2014-04-28 15:41:19 -07:00
Jonathan
2c95678be1 Merge pull request #451 from jcheng5/suppress-reactlog
Don't send reactlog messages to the client unless showcase mode
2014-04-28 14:52:42 -07:00
Joe Cheng
1a643cecf3 Allow naked renderXXX functions to be used inside other tags 2014-04-28 10:13:16 -07:00
Joe Cheng
aa10b2e8c4 Merge pull request #455 from trestletech/feature/subapp
Added extra query param to identify sub apps.
2014-04-28 09:33:37 -07:00
Joe Cheng
0b9317d047 Merge pull request #453 from yihui/feature/nocache
Prevent caching conditionally
2014-04-28 09:33:03 -07:00
Yihui Xie
4d58f05f38 fix the warning about stats not being imported in namespace
see https://travis-ci.org/rstudio/shiny/builds/23791246

but do we even have to import stats? I guess no; it is part of base R
2014-04-25 18:26:07 -05:00
trestletech
6e879c8156 Added extra query param to identify sub apps. 2014-04-25 11:30:48 -05:00
Yihui Xie
b6ee67aa41 make the selected argument of updateSelectizeInput() work even in the server mode 2014-04-25 02:38:38 -05:00
Yihui Xie
07bed0c7c7 factor out a function columnToRowData() so both updateSelectInput() and selectizeJSON() can use it 2014-04-25 02:37:45 -05:00
Yihui Xie
d2bd59d149 Make meta of length 0 when we are sure there are no dependencies
knitr::asis_output() will decide whether x is cacheable by checking length(meta) == 0. Some shiny tags are cacheable, such as numericInput(), because it is pure HTML without dependencies, whereas selectizeInput() is not cacheable due to the dependency on selectize.js.
2014-04-25 01:14:14 -05:00
Yihui Xie
7bdac5a44e Make sure shiny app objects are not cacheable using asis_output(..., cacheable = FALSE)
This commit reverts d08a2507fa
2014-04-25 01:14:08 -05:00
Joe Cheng
51f5db4374 Bump version 2014-04-24 16:38:07 -07:00
Joe Cheng
e395ae6555 Merge branch 'html-deps'
Code reviewed by @jmcphers

Conflicts:
	DESCRIPTION
	R/bootstrap.R
	R/reactives.R
2014-04-24 16:37:46 -07:00
Joe Cheng
1df9c498cf Ensure dep.meta is an array 2014-04-24 16:32:18 -07:00
Joe Cheng
57b3b919a5 Don't send reactlog messages to the client unless showcase mode 2014-04-24 16:05:54 -07:00
Joe Cheng
00c6bbb297 Merge pull request #449 from rstudio/bugfix/knitr-cached-shiny
Fail when attempting to insert a Shiny app into a cached knitr chunk
2014-04-24 15:50:05 -07:00
Joe Cheng
b6536a0af3 Merge pull request #445 from wch/str
Add str.reactivevalues
2014-04-24 15:49:21 -07:00
Jonathan McPherson
d08a2507fa fail when attempting to insert a shiny app into a cached chunk 2014-04-24 15:28:07 -07:00
Joe Cheng
8bc8829577 Merge pull request #448 from trestletech/rate-element
Add element argument to getRateCallback()
2014-04-24 10:01:42 -07:00
trestletech
c843e6f68c Bump version 2014-04-24 10:58:36 -05:00
trestletech
84583e5501 Add element argument to getRateCallback() 2014-04-24 10:13:06 -05:00
Winston Chang
4548562138 Fix argument name for S3 method 2014-04-23 15:03:49 -05:00
Joe Cheng
32c170b10a Remove Rmd examples 2014-04-23 13:02:40 -07:00
Joe Cheng
97dafa0a55 Include html-preserving comments in knit_print 2014-04-23 12:46:56 -07:00
Yihui Xie
0be1ee46f2 do not ignore the names of choices data 2014-04-22 17:58:19 -05:00
Winston Chang
34c9ab7643 Add str.reactivevalues 2014-04-21 21:59:49 -05:00
Joe Cheng
59dbca250f Fix roxygen 2014-04-21 16:50:06 -07:00
Joe Cheng
4028dbfda1 Do typeset mathjax on initial load
Fixes initial load not being typeset on e.g.:
https://gist.github.com/jcheng5/a0d123d58737590ac21e
2014-04-21 13:59:17 -07:00
Joe Cheng
b9dbf610b0 Fix bootstrap themes 2014-04-21 13:16:34 -07:00
Joe Cheng
d443810520 Use html_dependency for date inputs, datatables 2014-04-21 12:35:12 -07:00
Joe Cheng
fcd941d33d Use html_dependencies for showcase mode
For some reason, showcase mode was breaking sliders without this (e.g. 06_tabsets)
2014-04-21 12:34:54 -07:00
Yihui Xie
9c063fa37c bump version 2014-04-21 01:02:46 -05:00
Yihui Xie
2720cfe346 should use MathJax.Hub.Queue() instead of .Typeset(): finally solved the mysterious race condition issue
http://docs.mathjax.org/en/latest/typeset.html
2014-04-21 01:02:05 -05:00
Joe Cheng
c39e38081e Remove unused class 2014-04-18 16:29:13 -07:00
Joe Cheng
3deb4c3f42 Fix initial dependency handling, fix knit_print 2014-04-18 16:21:13 -07:00
Joe Cheng
6945091238 First attempt at HTML dependency management 2014-04-18 15:18:51 -07:00
JJ Allaire
c758c4785a bump version 2014-04-17 07:38:06 -04:00
Jonathan McPherson
19269a20fb fix subapps on portmapped URLs
Reviewed by @jcheng5
2014-04-16 13:08:57 -07:00
Joe Cheng
45669cacb1 Merge pull request #434 from jcheng5/private-random
Refactor private random seed code
2014-04-15 15:24:41 -07:00
Joe Cheng
840bc52aae Merge pull request #433 from yihui/selectize/server
server-side selectize input
2014-04-15 15:22:11 -07:00
Joe Cheng
bbc36e349f Merge pull request #439 from jcheng5/feature/uiPattern
Add uiPattern param to shinyApp to allow one ui to serve multiple URLs
2014-04-15 15:13:08 -07:00
Joe Cheng
a4325adcdd Add uiPattern param to shinyApp to allow one ui to serve multiple URLs
Reviewed by @jmcphers
2014-04-15 12:53:18 -07:00
Yihui Xie
23f39649d0 Merge pull request #438 from jcheng5/fix-roxygen
Fix PriorityQueue error message during roxygenize
2014-04-15 00:12:43 -05:00
Yihui Xie
87b09a534e Merge pull request #435 from jcheng5/null-input-labels
Allow NULL input labels; add actionLink
2014-04-14 22:59:28 -05:00
Yihui Xie
39f0e5ae0c fix some JShint issues 2014-04-14 22:53:08 -05:00
Yihui Xie
62aaab0926 closes #422: update the selectize options via updateSelectizeInput(options) 2014-04-14 22:34:48 -05:00
Yihui Xie
cddfe999aa cosmetic changes (re-indent code) 2014-04-14 22:28:45 -05:00
Joe Cheng
fcbb658ac2 Fix PriorityQueue error message during roxygenize 2014-04-14 15:37:06 -07:00
Joe Cheng
3bbf06ba49 Don't indent HTML during knit_print 2014-04-14 15:31:45 -07:00
Yihui Xie
d9be6f1d2e implementing the server-side selectize input
also added a new method shinysession$registerDataObj(), which was designed to be a general data retrieval method: we can store arbitrary data objects as "downloads", and return arbitrary http response based on the filter function; see renderDataTable() and updateSelectizeInput() for two examples
2014-04-13 00:02:08 -05:00
Yihui Xie
5d70e68a0b the development version of knitr can be installed from rforge.net 2014-04-12 12:33:42 -05:00
Joe Cheng
529f2325b2 Fix tests 2014-04-11 15:46:32 -07:00
Joe Cheng
314d433f86 Merge pull request #436 from rstudio/feature/shiny-docs
Improved support for R Markdown Shiny documents
2014-04-11 15:43:43 -07:00
Jonathan McPherson
12ea950c5f use more idiomatic syntax for resolving rmarkdown.runtime 2014-04-11 14:41:06 -07:00
Yihui Xie
f4d12220ca Merge pull request #437 from trestletech/winslash
Make normalizePath calls Windows-compatible.
2014-04-11 15:41:54 -05:00
Jonathan McPherson
6a9cba90f4 have validateCssUnit treat unit-free character strings as pixel units 2014-04-11 12:59:15 -07:00
trestletech
6873e1f1cb Make normalizePath calls Windows-compatible. 2014-04-11 14:55:51 -05:00
Joe Cheng
fa0a91a75d Fix createUniqueId logic 2014-04-11 12:06:22 -07:00
Joe Cheng
020bb659c5 Rename tempSet to withTemporary 2014-04-11 12:00:55 -07:00
Joe Cheng
b1d6687fb0 Fix private random seed mechanism
- Introduce randomInt/p_randomInt to generate random integers in a half-open range
- Stop using runif to generate integers
- Explicitly reset the private seed during .onLoad. I was getting the same "random" numbers from Shiny every time I restarted R!
2014-04-11 11:57:39 -07:00
Joe Cheng
f67e17b287 Allow NULL input labels; add actionLink 2014-04-11 11:00:41 -07:00
Jonathan McPherson
81bd57c5ea emit appropriate warnings in R Markdown mode; collect <head> contents 2014-04-11 10:53:25 -07:00
Joe Cheng
d803bae874 Bump ver 2014-04-11 10:17:51 -07:00
Joe Cheng
14606f4087 Remove unnecessary ::: 2014-04-11 10:16:59 -07:00
Joe Cheng
599fdc7ee5 Refactor private random seed code 2014-04-10 15:03:18 -07:00
Joe Cheng
722e205db5 Isolate createUniqueId randomness from rest of R
TODO: Generalize to our own runif

Reviewed by @jmcphers
2014-04-09 17:16:36 -07:00
Joe Cheng
f67849eb47 Doc cleanup 2014-04-09 17:10:37 -07:00
Joe Cheng
662ca4e40a Fix travis? 2014-04-09 16:28:36 -07:00
Joe Cheng
aa61be74d8 Merge pull request #432 from jcheng5/multiple-apps
Support reactive documents and embedded Shiny apps in rmarkdown
2014-04-09 16:23:43 -07:00
Joe Cheng
10296fcd6b Clear handler manager anytime runApp is called 2014-04-09 16:10:43 -07:00
Joe Cheng
f8bf146b6c Render functions can be inserted directly into .Rmd
All render functions need to call markRenderFunction on their
return values for this mechanism to work.

Also:
- Remove runRmdContainer (it's moved to rmarkdown)
- Remove some bad .Rbuildignore entries
- Make height/width in shinyApp respected
2014-04-09 14:53:56 -07:00
Joe Cheng
52f104c517 Automatically remove subapps when their owning session finishes 2014-04-08 16:38:45 -07:00
Joe Cheng
6c1fc224f0 Merge pull request #1 from jcheng5/reactive-domains
Reactive domains
2014-04-08 15:44:51 -07:00
Joe Cheng
6b9ae3a8b3 Move "@include globals.R" directives to top; slight doc fixes 2014-04-08 15:39:57 -07:00
Joe Cheng
07f73030c6 More reactive domain work
- observers' autodestroy behavior is now optional
- tests
2014-04-08 14:47:32 -07:00
Joe Cheng
47130c79ee Code review feedback 2014-04-08 11:16:42 -07:00
Joe Cheng
f3a3bdfe4f Port showcase mode execution highlighting to domains 2014-04-07 21:59:16 -07:00
Joe Cheng
e5e54fe4c1 Implement reactive domains 2014-04-07 21:55:05 -07:00
Joe Cheng
29c0f9a43a Ignore additional knit_print parameters 2014-04-07 17:10:44 -07:00
Joe Cheng
0b78229c77 Travis!! *shakes fist* 2014-04-07 11:45:46 -07:00
Joe Cheng
c2a1d70070 Fix travis 2014-04-07 10:54:21 -07:00
Joe Cheng
260ecd1d9f Travis: Install latest knitr master 2014-04-07 09:24:51 -07:00
Joe Cheng
3dce2e761a Fix debugging of server files
.global$server becomes appvars$server
2014-04-04 10:30:42 -07:00
Joe Cheng
80a54200ce Comment tweaks 2014-04-03 23:45:08 -07:00
Joe Cheng
51227d438a Get rid of "incomplete final line" warnings in showcase code 2014-04-03 21:33:40 -07:00
Joe Cheng
6fb4199d37 Make the worker ID global across all sub apps 2014-04-03 21:30:56 -07:00
Joe Cheng
6ba46aff6b Fix gitignores for literate 2014-04-03 21:02:18 -07:00
Joe Cheng
5da34d0646 Fix makefile on windows 2014-04-03 20:43:55 -07:00
Joe Cheng
f215088939 Update staticdocs index, tests pass 2014-04-03 19:43:11 -07:00
Joe Cheng
df34dcdb0c Pass R CMD check 2014-04-03 19:37:45 -07:00
Joe Cheng
89f464af99 Fix Rmd build tooling 2014-04-03 15:31:49 -07:00
Joe Cheng
3f6f02f7d2 More docs 2014-04-03 14:41:59 -07:00
Joe Cheng
0d861e5389 Add documentation for handlers/middleware 2014-04-03 14:24:55 -07:00
Joe Cheng
b290c8700c Allow the use of .Rmd files for shiny impl scripts 2014-04-03 11:12:16 -07:00
Joe Cheng
81b6fbe263 Remove obsolete print.shiny.appdir 2014-04-03 01:51:30 -07:00
Joe Cheng
b3af293f66 Fix scoping bug 2014-04-03 01:49:36 -07:00
Joe Cheng
b187485172 Major refactor of runApp/addSubApp pipeline
- shinyUI and shinyServer calls are no longer required in ui.R and server.R
- shinyAppObj renamed to shinyApp
- runApp can take pathname, list(ui=..., server=...), shinyApp, and shinyAppDir
  as appDir argument
- Unify all Shiny app representations around shiny.appobj
- BREAKING CHANGE: shinyUI no longer has a "path" argument
- Instead of returning UI, ui.R can return a function that returns UI; it will
  be invoked each time the page is requested. (Note that this is NOT the same
  as saying ui.R will be run each time the page is requested.) The function can
  take either no args or a single "req" arg which is the request.
2014-04-03 01:42:01 -07:00
Joe Cheng
b449d9759c Minor doc updates 2014-04-01 23:02:22 -07:00
Joe Cheng
d9d63a3a2e Painful refactoring of server.R
This refactor changes the level of abstraction where sub-apps are implemented.
Sub-apps can basically be thought of as routing (previously called "proxying"
which was way too confusing). A call comes in to /1e8f937a8934/ and it matches
a sub-app path--we need to change the path from /1e8f937a8934/ to / for the
duration of the sub-app's handling of the request.

We used to do routing (nee proxying) at the httpuvCallback level, which added
a lot of complexity because it meant we were compositing HTTP handlers at both
the httpHandler level, and then again at the httpuvCallback level. This
refactor changes it so nobody speaks the language of httpuv except at the very
boundary of Shiny (webserver$createHttpuvApp), everything inside is either an
httpHandler or a wsHandler. So whether you're combining or routing or whatever,
everything now works the same way.
2014-04-01 22:55:56 -07:00
Joe Cheng
fd7b54fb77 Clean up exports, examples 2014-03-31 16:40:17 -07:00
Joe Cheng
887f8a606d Restore index.r entries for app obj 2014-03-31 12:11:16 -07:00
Joe Cheng
7e3717243f Merge remote-tracking branch 'origin/master' into multiple-apps
Conflicts:
	staticdocs/index.r
2014-03-31 12:08:59 -07:00
Joe Cheng
221849aa3a More-correct impl of %OR% 2014-03-31 12:07:57 -07:00
Joe Cheng
b52d40ab28 Merge pull request #430 from rstudio/v0.10
V0.10
2014-03-31 11:55:29 -07:00
Joe Cheng
3ed68ffd92 knit_print tags and tagLists 2014-03-31 11:17:24 -07:00
Joe Cheng
cc3cd2c141 Implement Shiny apps embedded as iframes in knitr 2014-03-31 10:03:22 -07:00
Winston Chang
5e30f7efc4 Merge pull request #424 from rstudio/bugfix/zero-arg-sourcerefs
Handle zero-argument outputs gracefully
2014-03-27 12:48:41 -05:00
Yihui Xie
35090251ef basically library(pkg) = if (!require(pkg)) stop() 2014-03-24 23:49:34 -05:00
Yihui Xie
338afb4893 change the deprecated @S3method to @export 2014-03-24 23:46:46 -05:00
Yihui Xie
194d8a05f8 using the latest master of klutometis/roxygen (d823c3a088b20ea5e38a60d78d42ccbe9f1e1eec)
Rd text for arguments is no longer wrapped by default
2014-03-24 23:46:46 -05:00
Winston Chang
93e276bd9b Fix capitalization of markdown package 2014-03-24 12:35:12 -05:00
Winston Chang
a69517519c Add more information to selectInput docs 2014-03-21 16:30:25 -05:00
Winston Chang
f646b1efb4 Bump version to 0.9.1.9000 for development 2014-03-21 16:16:53 -05:00
Jonathan McPherson
fc9bedacc0 guard against null source references 2014-03-20 16:00:51 -07:00
Jonathan McPherson
795eeee809 handle no-argument output calls gracefully 2014-03-20 15:46:25 -07:00
Joe Cheng
6d7818962e Redirect on no trailing slash 2014-03-20 10:14:02 -07:00
Joe Cheng
068517c933 Prevent multiple apps from stomping on server func 2014-03-20 09:09:54 -07:00
Joe Cheng
5b030200df initial prototyping of subapps 2014-03-20 08:49:18 -07:00
Joe Cheng
c732122966 Merge pull request #421 from jcheng5/bugfix/context-new
Fix 'Error in Context$new : could not find function "loadMethod"'
2014-03-19 11:40:19 -07:00
Joe Cheng
d7eb9b2d18 Fix 'Error in Context$new : could not find function "loadMethod"'
This warning was happening to dependent packages on R CMD check.

The problem is due to delayedAssign; it appears this can't be used safely, at least not to define package-level symbols that contain S4 or reference class objects.

If you call this in a package's .R file:

`delayedAssign("hello", stop("boom"))`

but don't refer to "hello" anywhere, when you run R CMD check on a dependent package you'll see the error.

If the expression needs the methods package (like Context$new()), you'll get an error unless the dependent package itself depends on methods.
2014-03-19 09:49:33 -07:00
Yihui Xie
b8b09adda1 submit shiny 0.9.0 to CRAN 2014-03-18 14:32:46 -05:00
Yihui Xie
07c8f0c4b7 use skipStartupTypeset: true for MathJax config, and call MathJax.Hub.Typeset() later
setTimeout() is necessary for uiOutput(); we need to wait for a short while before typesetting math, otherwise two bad things can happen:

1. a math expression may be rendered twice (static output)
2. it is not rendered at all (dynamic ui output)

so the compromise is to typeset math after a short while when the document is ready; 200 ms is an arbitrary choice here
2014-03-18 14:24:23 -05:00
Joe Cheng
2bd201de63 Refactor server logic into separate file 2014-03-17 16:08:59 -07:00
Joe Cheng
0b7e118a37 Merge branch 'staticdocs-0.9.0' into v0.10
Conflicts:
	staticdocs/index.r
2014-03-17 14:40:45 -07:00
Joe Cheng
a546769225 Use new staticdocs packaging standards 2014-03-17 14:37:38 -07:00
Joe Cheng
81745f932d Include withMathJax in staticdocs; improve test 2014-03-17 14:07:05 -07:00
Joe Cheng
4415bf31d2 Mention showcase mode and allow-dots in NEWS 2014-03-13 14:33:25 -07:00
Joe Cheng
5c1bcb41d8 Merge pull request #418 from jcheng5/allow-dots
Allow '.' character in input/output IDs

Fixes #358
2014-03-13 14:25:56 -07:00
Joe Cheng
b659c4c2bb Proper escaping of name, value, and type queries 2014-03-13 12:18:21 -07:00
Joe Cheng
65adc8a405 Wrap for= value in double quotes 2014-03-13 10:16:07 -07:00
Joe Cheng
4141f78717 It's important to return values in JS. heh. 2014-03-13 10:13:26 -07:00
Joe Cheng
80cb02d206 Allow '.' character in input/output IDs
I always thought dots and colons were illegal in HTML ID attributes,
but I was wrong. They are legal and because they are commonly used
in identifier names in R, Shiny users often like to use them. Worse,
Shiny gave no warnings when using dots and only a pretty advanced
subset of functionality would NOT work when using dots, causing
everyone to think they were fully supported in Shiny.

This commit ought to bring reality in line with perception. It turns
out that jQuery has an escaping scheme in its queries that allow us
to support dots after all. As long as we are always careful to
surround IDs with $escape when putting them in a query, we'll be in
good shape.

Colons will probably still cause problems at the moment because we
use colons internally to separate input type from input name. But
we've never seen users try to use colon in IDs before, so we can
wait to fix it until that becomes a problem.
2014-03-12 17:39:05 -07:00
Joe Cheng
a5a4510a1e Merge pull request #417 from yihui/bugfix/showcase-escape
fixes #416: use tags$code() to escape the code in showcase mode
2014-03-11 21:09:48 -07:00
Yihui Xie
95c30649d3 fixes #416: use tags$code() to escape the code in showcase mode
and format(..., indent = FALSE) to prevent indentation of <code>
2014-03-11 22:40:16 -05:00
Joe Cheng
8e5cbde08c Change example licenses to MIT 2014-03-11 10:49:32 -07:00
Yihui Xie
6df8632e29 Merge pull request #414 from jcheng5/bugfix/selectize-order
Fix selectize misordering on updateSelectInput
2014-03-11 11:55:26 -05:00
Jonathan
3c1218fff1 Merge pull request #415 from jcheng5/bugfix/showcase-case
Make showcase mode work with .r files
2014-03-11 09:13:04 -07:00
Joe Cheng
69c0414791 Make showcase mode work with .r files 2014-03-11 09:08:20 -07:00
Joe Cheng
d63f83fcbb Fix selectize misordering on updateSelectInput
Repro case at https://gist.github.com/jcheng5/9403917
2014-03-06 18:27:02 -08:00
Joe Cheng
75c3bf0c2f Change version to 0.9.0 2014-03-06 10:20:25 -08:00
Joe Cheng
c9a8ab2389 Merge pull request #411 from yihui/selectize/backspace
Selectize backspace issue
2014-03-05 00:29:44 -08:00
Yihui Xie
2c467c00e1 10px bottom margin for selectize input 2014-03-04 16:53:29 -08:00
Yihui Xie
c63ec5a1f2 update the test for selectInput() accordingly 2014-03-03 12:02:39 -08:00
Yihui Xie
e886558cbb roxygenize 2014-03-03 12:02:39 -08:00
Yihui Xie
8dd6dabe50 add selectize=TRUE to selectInput(), but disable deletion for single input
hopefully this is a good compromise for #404
2014-03-03 12:02:39 -08:00
Joe Cheng
c090c6adf9 Merge pull request #410 from wch/faster-tags-2
Faster tags
2014-02-28 09:43:57 -08:00
Yihui Xie
84da0befcd fixes #306: remove the possible trailing slash under Windows
the cause:

normalize('foo',  '/') => C:/foo
normalize('foo/', '/') => C:/foo/

under Windows. For unix, the trailing slash will always be removed in normalizePath()
2014-02-27 18:17:50 -06:00
Yihui Xie
267751c8b9 we have specified winslash='/' before, so it is impossible that this char is \ 2014-02-27 17:59:14 -06:00
Winston Chang
8add9f7188 Restructure logic and simplify 2014-02-27 16:02:30 -06:00
Yihui Xie
a100b0991b closes #119: we do not have to do this special treatment to the label for sliderInput, and no other inputs do as.character() for their labels
if users pass an HTML() object to the label argument, the HTML will be preserved instead of being escaped
2014-02-25 23:58:59 -06:00
Winston Chang
9ce9c5e535 More tag writing tweaks 2014-02-25 23:16:50 -06:00
Yihui Xie
b2d004ca1a closes #31: try to avoid scientific notation of numbers 2014-02-25 22:58:08 -06:00
Yihui Xie
657d50f9a3 add the missing Readme's and DESCRIPTION's for the examples 2014-02-25 21:18:16 -06:00
Joe Cheng
60e355c4f5 Faster singleton detection 2014-02-25 18:56:47 -08:00
Yihui Xie
adb444a60f the original hello-world example makes little practical sense -- it is unclear what really changed when moving the slider, especially when obs is large (we always see a "bell-shaped" histogram)
let's make the number of bins reactive instead; now it is very clear what the slider really controls

a histogram with different number of bins also serves as a good demo of the property of histograms (small bins --> small variance + large bias)
2014-02-25 20:44:19 -06:00
Yihui Xie
e7e13ff70d document the new features of DataTables in NEWS 2014-02-25 19:48:46 -06:00
Yihui Xie
a1e81db597 roxygenize 2014-02-25 19:25:48 -06:00
Yihui Xie
f23f2ff0a0 the url of selectiz.js is already in Details 2014-02-25 19:25:48 -06:00
Yihui Xie
c1b18098f1 Revert "add selectize=TRUE to selectInput(), instead of adding a separate function selectizeInput(), per suggestion of @jjallaire"
This reverts commit d3115a3bf3 and closes #404
2014-02-25 19:25:33 -06:00
Joe Cheng
31c39592e3 Faster tag rendering 2014-02-25 16:37:54 -08:00
Yihui Xie
82a1dad22a roxygenize 2014-02-25 15:45:59 -06:00
Yihui Xie
1ecec24727 add a callback argument in renderDataTable() so that users can have access to the DT object 2014-02-25 15:44:00 -06:00
Yihui Xie
607841e947 cosmetic changes 2014-02-25 15:42:36 -06:00
Yihui Xie
e234b403ae when the options is null, also show the search boxes 2014-02-25 00:41:57 -06:00
Yihui Xie
80ce7a36f8 make it possible to filter numeric columns based on the specified range of the form "lower,upper" 2014-02-24 23:59:12 -06:00
Yihui Xie
705a8666be iDisplayLength == -1 means "display all data" (#400)
we can use this feature via several ways, e.g.

- renderDataTable(..., options = list(bPaginate = FALSE))
- iDisplayLength = -1
- aLengthMenu = list(c(10, 30, -1), list(10, 30, 'All'))
2014-02-24 23:31:28 -06:00
Yihui Xie
9167905118 respect the bRegex option (as well as bRegex_j for individual columns)
however, this option is not part of the initialization options, so actually users can never use it...

#400
2014-02-24 23:29:10 -06:00
Yihui Xie
bdeb6734d8 data.options is null by default 2014-02-24 21:46:50 -06:00
Yihui Xie
9a7b042594 respect the individual bSearchable_j options in datatables 2014-02-24 21:02:25 -06:00
Winston Chang
7aea256fd8 Use YYYY/MM/DD format only as a fallback 2014-02-24 16:43:49 -06:00
Yihui Xie
857b5e6932 Merge pull request #406 from wch/date-ie8
Add function for handling date strings in IE8
2014-02-24 16:24:35 -06:00
Winston Chang
1a2d675439 Add function for handling date strings in IE8 2014-02-24 16:02:57 -06:00
Yihui Xie
0c749643de Merge pull request #405 from jcheng5/bugfix/ie8-debounce
Fix debounce error in IE8
2014-02-24 15:46:03 -06:00
Winston Chang
09bb1548f9 Fixes for jshint 2014-02-24 15:35:01 -06:00
Joe Cheng
5ffe531844 Fix debounce error in IE8
In the repo https://github.com/rstudio/shiny-testapp/ the test app
called "setinput" threw errors in IE8 due to the debouncer getting
triggered incorrectly. Essentially Debouncer.$invoke was being
called twice without an intervening normalCall or immediateCall,
which caused apply to be called with this.args === null. Upon
careful inspection/debugging it seems like this may be a bug in the
IE8 implementation of setTimeout/clearTimeout:
http://stackoverflow.com/questions/5853571/clarifying-cleartimeout-behavior-in-ie

In any case, the workaround is to check for a null timer id, which
means we tried to clear the timer at least.
2014-02-24 13:14:17 -08:00
Yihui Xie
fab24a3200 httpuv 1.2.3 is in marutter precise ppa now
hopefully this can save some time for travis ci
2014-02-23 11:09:54 -06:00
Yihui Xie
899d5e9d1d spent two hours on this weird issue of disappearing checkboxes and radio buttons, just to find two missing backslashes for <label>
http://api.jquery.com/jQuery/#creating-new-elements
2014-02-22 01:01:49 -06:00
Joe Cheng
ba510884f2 Avoid using browser URL with host of 0.0.0.0
(reviewed by @jmcphers)
2014-02-21 14:58:19 -08:00
Joe Cheng
78e8df8e17 Fix tags$head + renderUI in IE8, which was broken
Repro case: https://github.com/rstudio/shiny-testapp/tree/master/dynamic_singletons

Reviewed by @jmcphers
2014-02-21 10:15:03 -08:00
Yihui Xie
deba1609c3 implement bSearchable for individual columns (#400)
if a column is not searchable, hide its search box
2014-02-20 18:29:44 -06:00
Yihui Xie
88d2425ca3 respect the bFilter option: when it is false, do not show the search boxes 2014-02-20 18:21:36 -06:00
Yihui Xie
7117f9e058 closes #392: options in renderDataTable() can also take a function to return a list 2014-02-20 16:55:44 -06:00
Yihui Xie
c21c407416 a few cosmetic changes
= to <-, and camelCase instead of under_score
2014-02-20 16:44:09 -06:00
Yihui Xie
4b4ad42063 xtable was built from R < 3.0.0 in the official ubuntu repo hence fails to load 2014-02-20 15:09:42 -06:00
Yihui Xie
474d514c7d the httpuv binary is not in the marutter/c2d4u PPA yet
we can wait for a couple of days and revert this commit
2014-02-20 14:48:08 -06:00
Yihui Xie
6239466da8 klutometis/roxygen#191 has been fixed, so no longer need explicit @usage 2014-02-20 14:30:51 -06:00
Yihui Xie
7746d75582 bug fix: when evalOptions is of length 1, toJSON() converts it to a scalar; we need to use I() to make sure it is always a vector so that we can later $.each() 2014-02-20 14:24:51 -06:00
Yihui Xie
642c9ded08 install some R package dependencies through apt-get instead of R to save time 2014-02-20 13:42:39 -06:00
Joe Cheng
e0ae931ddd Merge pull request #402 from rstudio/bugfix/ie8-compatibility
Bugfix/ie8 compatibility
2014-02-20 10:24:10 -08:00
Jonathan McPherson
0d7727a405 fix Markdown content extraction on IE8 2014-02-20 10:22:43 -08:00
Joe Cheng
28f689498a fix browser height detection and CSS on IE8 2014-02-20 09:16:18 -08:00
Yihui Xie
eb8fec7f2d when searching is turned on, we need to make sure the filtering indices i are smaller than nrow(filtered data) instead of original data
this fixes the bug reported at https://groups.google.com/forum/#!topic/shiny-discuss/xk2Gh7KJQBM
2014-02-19 23:09:25 -06:00
Yihui Xie
2e16fa1d70 fixes #401: pass numbers as character strings in updateNumericInput() to preserver numeric precision when possible 2014-02-19 22:11:39 -06:00
Jonathan McPherson
1b856c4909 use IE8-compatible events; turn off highlighting in IE8 2014-02-19 16:45:58 -08:00
Jonathan
585ad30af1 Merge pull request #396 from jcheng5/bugfix/395-monospace-fonts-qt
Fix issue #395: Monospace fonts broken on QtWebKit
2014-02-19 16:32:38 -08:00
Joe Cheng
c0cdc4083c Merge pull request #397 from yihui/select2
Selectize.js
2014-02-19 15:45:56 -08:00
Joe Cheng
9b9db4f161 Merge pull request #398 from jcheng5/feature/suppress-tag-indent
Add indent argument to format.shiny.tag
2014-02-19 15:21:51 -08:00
Joe Cheng
84a1d8d25e Add comment about format.shiny.tag's indent param 2014-02-19 15:21:28 -08:00
Yihui Xie
d3115a3bf3 add selectize=TRUE to selectInput(), instead of adding a separate function selectizeInput(), per suggestion of @jjallaire 2014-02-19 12:04:23 -06:00
Yihui Xie
964789e9a6 add a note in the NEWS that DataTables also works for IE8 now 2014-02-19 11:58:34 -06:00
Yihui Xie
eeded51ff8 IE8 does not have map() and forEach() methods
use $.each() and $.map() instead
2014-02-19 11:58:34 -06:00
Yihui Xie
8f24f1b4d6 localize es5-shim.js 2014-02-19 11:58:34 -06:00
Yihui Xie
ad910a295a For IE8, $.text() does not work on <script>, so use $.html() instead 2014-02-19 11:58:34 -06:00
Yihui Xie
cf14c6b1e9 add es5-shim.js for IE8 2014-02-19 11:58:34 -06:00
Yihui Xie
49da114caa add a note about the I() options in selectizeInput() 2014-02-19 11:58:34 -06:00
Yihui Xie
b8376ebbf7 it is safer to evaluate the string inside ()
e.g. one cannot directly evaluate {a: 1, b: 2}, although it is legitimate JSON; eval("({a: 1, b: 2})") always works
2014-02-19 11:58:33 -06:00
Yihui Xie
29701d7295 apply checkAsIs() to selectizeInput(), and store the names in data-eval in the script
note we switched the order of {} and config.text() in $.extend(), so that users can overwrite the default options like labelField, valueField, ...
2014-02-19 11:58:33 -06:00
Yihui Xie
16279695a9 factor out the code to determine which options should be evaluated into a utility function checkAsIs(), so that it can be applied to selectizeInput() as well 2014-02-19 11:58:33 -06:00
Yihui Xie
999fc86bc6 news for selectizeInput() 2014-02-19 11:58:33 -06:00
Yihui Xie
0276d533fb the search field must be renamed accordingly 2014-02-19 11:58:33 -06:00
Yihui Xie
b77fc34a7b new function selectizeInput() to use selectize.js
closes #287
2014-02-18 23:25:25 -06:00
Joe Cheng
60c450d57e Add indent argument to format.shiny.tag 2014-02-18 12:55:11 -08:00
Joe Cheng
73411c75db Fix staticdocs test on Linux 2014-02-18 12:52:59 -08:00
Yihui Xie
8d146f7dff Revert "math expressions may come in through renderUI()/uiOutput(), in which case we have to re-typeset the math expressions"
This reverts commit 58471c6971.
2014-02-17 18:52:25 -06:00
Yihui Xie
5c34aa0bb5 remove includeMathJax() and use withMathJax() instead, per suggestion of @jcheng5 2014-02-17 18:52:25 -06:00
Joe Cheng
2b2ed8162d Staticdocs prefers lower-case .r on linux 2014-02-17 16:40:08 -08:00
Joe Cheng
9770bd8005 Tweak two Rd titles 2014-02-17 16:01:57 -08:00
Yihui Xie
4e020818ae white spaces 2014-02-17 14:43:33 -06:00
Yihui Xie
58471c6971 math expressions may come in through renderUI()/uiOutput(), in which case we have to re-typeset the math expressions 2014-02-17 14:43:33 -06:00
Joe Cheng
2a2e02bf56 Remove border radius on showcase well 2014-02-17 11:34:07 -08:00
Joe Cheng
75d8cee766 Fix issue #395: Monospace fonts broken on QtWebKit 2014-02-17 11:31:39 -08:00
Joe Cheng
1aed36bd16 Revert "Merge pull request #298 from jcheng5/remove-catools"
This reverts commit 0ad9a5f9c6, reversing
changes made to c31d91668a.
2014-02-14 13:35:41 -08:00
Joe Cheng
00ce58ed18 Merge pull request #390 from dmbates/patch-2
Update server.R
2014-02-12 13:50:49 -08:00
Douglas Bates
d11aa1a61c Update server.R
Minor typo
2014-02-12 15:25:30 -06:00
Yihui Xie
56a62d3b4d Merge pull request #356 from yihui/feature/datatables-options
To be able to evaluate options passed to DataTables
2014-02-11 23:19:13 -06:00
Yihui Xie
e6dd668657 news for #356 2014-02-11 23:18:32 -06:00
Yihui Xie
f60a64c8db instead of assuming fnFooBar should be evaluated, let's use I() explicitly 2014-02-11 23:12:19 -06:00
Yihui Xie
eff1c298c9 it is okay to include README.md in an R package on CRAN now 2014-02-11 22:59:37 -06:00
Yihui Xie
358b0a122b ignore staticdocs/ when building the source package 2014-02-11 22:59:37 -06:00
Yihui Xie
c0f7ba9d46 use Rd2roxygen to convert the two manually written Rd files to roxygen comments, so that all Rd files are automatically generated from roxygen2 now 2014-02-11 22:59:37 -06:00
Yihui Xie
c4edae8196 using roxygen2 4.0.0: the spurious changes are due to klutometis/roxygen#184 (text in Rd is no longer wrapped by default) 2014-02-11 22:59:37 -06:00
Yihui Xie
398dab808c use @include to make sure the Collate field is correctly generated 2014-02-11 22:59:37 -06:00
Yihui Xie
3530871560 strip white spaces 2014-02-11 22:59:37 -06:00
Yihui Xie
1ba26fdb98 tweak news 2014-02-11 22:31:21 -06:00
Joe Cheng
a3b85b4e3e Add index entry for absolutePanel 2014-02-11 14:19:04 -08:00
Joe Cheng
e37a5d0394 Merge remote-tracking branch 'jcheng5/feature/absolute-panel'
Conflicts:
	NEWS
	man/validateCssUnit.Rd
2014-02-11 14:17:58 -08:00
Yihui Xie
e5a8e77e2a Merge pull request #364 from yihui/feature/mathjax
closes #25: a new function includeMathJax()
2014-02-11 16:06:48 -06:00
Yihui Xie
314b59798f a news item for includeMathjax() 2014-02-11 16:06:20 -06:00
Yihui Xie
e9ae16e534 closes #25: a new function includeMathJax() 2014-02-11 15:59:23 -06:00
Joe Cheng
c971ca0ce2 Merge pull request #388 from rstudio/feature/example-display-mode
Allow display.mode to be provided for examples
2014-02-11 12:45:11 -08:00
Joe Cheng
0ad9a5f9c6 Merge pull request #298 from jcheng5/remove-catools
Remove caTools dependency
2014-02-11 12:40:09 -08:00
Joe Cheng
c31d91668a Suppress staticdocs test when run on a built package 2014-02-10 11:58:40 -08:00
Jonathan McPherson
f5c196d717 allow display.mode to be provided for examples 2014-02-10 10:40:34 -08:00
Joe Cheng
3b90eed89f Add check for staticdocs index correctness 2014-02-05 13:45:25 -08:00
Joe Cheng
9828c8b787 Minor doc tweaks
- Combine sliderInput and animationOptions topics
- Provide better staticdoc index descriptions

Sorry for the big diff, that's due to using a newer version of roxygen.
2014-02-05 13:23:57 -08:00
Winston Chang
b3e997134f Merge branch 'bugfix/381-sendOutputHiddenState' 2014-02-05 12:30:39 -06:00
Winston Chang
f560baa69b Add comments about debouncing 2014-02-05 12:30:25 -06:00
Winston Chang
8cf5f00c87 Remove console logging code 2014-02-05 12:12:38 -06:00
Winston Chang
482c3895d3 Udpate to jQuery 1.11.0
This makes the following JS console message (as noted in #271) go away:
event.returnValue is deprecated. Please use the standard event.preventDefault() instead.
2014-02-05 12:07:28 -06:00
Joe Cheng
fc0d4bde35 Staticdocs index info 2014-02-04 16:13:37 -08:00
Joe Cheng
33ed89a036 Merge pull request #363 from yihui/text-output-container
fixes #90: textOuput() can be put in any tag now
2014-02-03 16:44:08 -08:00
Joe Cheng
0a5953c104 Remove caTools dependency 2014-02-03 16:41:28 -08:00
Joe Cheng
77f6be1a8b Fix URL for slider number format details
Fixes issue #384
2014-02-03 16:37:22 -08:00
Yihui Xie
5bd3f9a571 just to avoid the spurious warning in R CMD check "doRenderTags: no visible binding for global variable 'htmlResult'" 2014-01-30 21:27:43 -06:00
Yihui Xie
ef59119663 Merge pull request #383 from jcheng5/bugfix/broken-image
Don't show broken image when plot is empty
2014-01-30 19:09:08 -08:00
Joe Cheng
45baca7018 Don't show broken image when plot is empty
Repro case:

shiny::runApp(list(
  ui=basicPage(plotOutput('foo')),
  server=function(input, output, session) {
    output$foo <- renderPlot({})
  }
))
2014-01-30 16:46:07 -08:00
Joe Cheng
9b1edb7a97 Fix issue #381: sendOutputHiddenState is called too many times 2014-01-30 10:18:43 -08:00
Yihui Xie
31c071d086 use values instead of names for radioButtons due to #340
the problem was revealed from #377
2014-01-27 22:55:37 -06:00
Joe Cheng
ecf4c5c104 Merge pull request #376 from wch/singleton
Add exports.renderHtml function
2014-01-22 14:35:23 -08:00
Winston Chang
35fbfece0d Export renderHtml function and un-export singletons object 2014-01-21 13:14:21 -06:00
Winston Chang
b7721e42d3 Fixes for jshint 2014-01-21 10:19:50 -06:00
Winston Chang
386346cee9 Add new object for handling singletons 2014-01-21 10:19:50 -06:00
Winston Chang
bbecccc45e Missing semicolon 2014-01-21 10:02:52 -06:00
Yihui Xie
1a8f84c134 and reactive({}) also works; closes #366 2014-01-17 22:41:00 -06:00
Yihui Xie
66181fdcdf reactive(NULL) works now 2014-01-17 22:40:13 -06:00
Winston Chang
b9c05e8a9c Bind both mouse and touch events for jslider
This brings in commit 468002a for jslider. It fixes the problem where
dragging the slider didn't work in the RStudio viewer pane.
2014-01-17 09:36:31 -06:00
Joe Cheng
9c22d6c12a Merge pull request #371 from trestletech/no-write-closed
Don't attempt to write if the connection is closed.
2014-01-16 16:41:23 -08:00
trestletech
f3cedbbd6f Don't attempt to write if the connection is closed. 2014-01-16 14:34:55 -06:00
Joe Cheng
3f3a660ca1 Merge pull request #369 from trestletech/input-handler-patch
Define a non-S3 input registry.
2014-01-16 11:37:28 -08:00
Joe Cheng
1c6ded8416 Merge pull request #370 from trestletech/flush-on-session-end
Flush react/output onSessionEnd
2014-01-16 11:13:16 -08:00
trestletech
aa63fdb26f Flush react/output onSessionEnd 2014-01-16 12:26:29 -06:00
trestletech
3932330ce6 Added tests, stop converting NULLs to NA. 2014-01-15 14:24:13 -06:00
trestletech
3b946b1c69 Removed deprecated function documentation. 2014-01-14 21:26:04 -06:00
trestletech
14df829f18 Update inputHandler docs, revamped tests. 2014-01-14 21:19:12 -06:00
trestletech
788d024be6 Define a non-S3 input registry.
Revises the approach taken in #233.

!! No longer casts NULLs in incoming JSON to NA.
2014-01-14 18:02:19 -06:00
Joe Cheng
c20b56e089 Merge pull request #367 from jcheng5/bugfix/dynamic-singleton
Better handling of dynamically generated singletons
2014-01-14 10:41:10 -08:00
Joe Cheng
287f4f239e Better handling of dynamically generated singletons
Ref:
https://groups.google.com/d/msg/shiny-discuss/cgSHsM1FCjY/vgU1-jmkGjkJ

The user reported that on a page with multiple uiOutputs whose corresponding
renderUI calls all returned sliderInputs (but no sliderInput was present in
ui.R), some but not all of the sliders were initialized correctly; the ones
that were not didn't receive the jquery-slider treatment and just looked like
text boxes.

This was caused by a fundamental flaw in our handling of singletons in
renderUI. The implicit assumption in the old renderUI code was that:

1) Any HTML we generate in renderUI would be rendered in the client
2) Given multiple calls to renderUI, the HTML we return will be rendered in
   the client in the order that we generated it

Both assumptions are incorrect. #1 would be incorrect in cases where an output
is rendered twice before flushOutput is called (this is possible when using an
observer to modify a reactive input, for example), and #2 is incorrect when
output is flushed with multiple values (very common, and exactly what was
happening to the user scenario linked above).

This commit fixes the problem by deferring singleton-handling for uiOutput to
the client. We don't assume that a singleton has been rendered until right
before we render it. The implementation uses a surroundSingletons function on
the server side to surround all singletons with <!--SHINY.SINGLETON[sig]-->
and <!--/SHINY.SINGLETON[sig]-->, which will then be parsed and removed in
the htmlOutputBinding in shiny.js. (And because singletons may contain <head>
elements, we also need to defer <head> hoisting to htmlOutputBinding as well.)

The context$filter mechanism previously used in tagWrite was not flexible
enough to handle this kind of singleton processing. The new rewriteTags
function does tag walking and rewriting much more robustly and flexibly than
context$filter, so I also refactored renderTags to use it instead.

One unrelated problem I noticed was that singleton only worked reliably on
tags, possibly on characters and definitely not on list() or tagList(). This
is because list flattening was happening at tag construction time, which
can cause singleton objects to be trampled. (Among other reasons, such as
context$filter not being called on list objects.) I changed tags.R to not do
any flattening or NULL dropping at tag construction time, but instead to do
it at the last minute during tagWrite.
2014-01-13 17:04:30 -08:00
Joe Cheng
dce66945ec Merge pull request #340 from yihui/bug/null-choices
fix the bug when choices=NULL in updateCheckboxGroupInput()
2014-01-11 13:43:05 -08:00
Yihui Xie
92bd1d5200 Merge pull request #360 from jcheng5/bugfix/359-factors-as-numbers
Fix issue #359: Factors in HTML attributes are being converted to their numeric, not character, equivalent
2014-01-10 19:30:33 -08:00
Yihui Xie
06d2df8211 fixes #90: textOuput() can be put in any tag now
for the example, we use <span>, which is allowed in <h3>
2014-01-10 20:54:28 -06:00
Joe Cheng
36256856b5 Fix issue #359: Factors in HTML attributes are being converted to their numeric, not character, equivalent
This bug was introduced in 3fc1410. Essentially it boils down to the difference between stringifying a factor, and stringifying a list containing a factor:

> as.character(factor('a'))
[1] "a"
> as.character(list(factor('a')))
[1] "1"
The call to split that was introduced in this commit ends up generating lists of factors, not vectors of them.

The best fix I could find was to convert all the attribute values to character before doing the split.
2014-01-10 01:48:02 -08:00
Joe Cheng
a771ae853c Remove extraneous library calls 2014-01-09 10:44:50 -08:00
Yihui Xie
ef4e10bbb1 Merge pull request #355 from jcheng5/bugfix/null-children
Ignore NULL tag elements
2014-01-08 18:51:20 -08:00
Yihui Xie
0dbe4d936e cosmetic changes, just because Github is not aware of my new commits for the PR after it was down 2014-01-08 16:23:23 -06:00
Yihui Xie
731fee11d4 a missing space 2014-01-08 15:54:05 -06:00
Yihui Xie
6759df52c3 show the log files after R CMD check failures 2014-01-08 15:18:01 -06:00
Yihui Xie
914b997076 need to run roxygen2 2014-01-08 15:18:01 -06:00
Yihui Xie
0b8a2fea72 and a missing ) 2014-01-08 14:47:40 -06:00
Yihui Xie
fb2538135c an extra ) 2014-01-08 14:46:57 -06:00
Yihui Xie
b4c547c278 move assignments out, per suggestion of @hadley 2014-01-08 14:22:38 -06:00
Yihui Xie
b243bc846b also include input ID in the warning message, per suggestion of @jcheng5 2014-01-08 14:21:41 -06:00
Joe Cheng
6b8f6162b6 Unify jqueryui copies 2014-01-08 09:41:38 -08:00
Joe Cheng
158db1532b Merge remote-tracking branch 'origin/master' into feature/absolute-panel
Conflicts:
	DESCRIPTION
2014-01-08 09:32:14 -08:00
Jonathan
6abfdb59c6 Merge pull request #352 from rstudio/feature/showcase-mode
Add Shiny Showcase mode
2014-01-08 09:11:24 -08:00
Jonathan McPherson
009d1f9ced make runApp arg take precedence over DESCRIPTION for setting showcase mode 2014-01-08 08:55:30 -08:00
Yihui Xie
555fba6598 Merge pull request #348 from rstudio/feature/navbar-input-binding
add id parameter to navbarPage (support for tab input binding)
2014-01-07 20:47:44 -08:00
Jonathan McPherson
f9017b72a7 remove extraneous parameter to startAppDir 2014-01-07 16:17:16 -08:00
Joe Cheng
99c3c2fc80 Ignore NULL tag elements
We already do the right thing for NULL tag attributes
2014-01-07 15:59:42 -08:00
Jonathan McPherson
32381679f2 update display.mode parameter and width for inputs 2014-01-07 15:50:43 -08:00
Jonathan McPherson
3d031265d1 satisfy R CMD CHECK: validate srcfile, use with(tags rather than withTags 2014-01-07 12:51:03 -08:00
Jonathan McPherson
026cda0071 change DESCRIPTION Type field from ShinyShowcase to Shiny 2014-01-07 11:16:46 -08:00
Jonathan McPherson
fb41ed5a86 make display.mode symmetric with DisplayMode in DESCRIPTION 2014-01-06 15:56:53 -08:00
Jonathan McPherson
8a08468a73 improve code density and zoomed display of inputs 2014-01-06 14:45:05 -08:00
Jonathan McPherson
f600cb4f2c allow source highlighting in files other than server.R 2014-01-06 14:33:31 -08:00
Jonathan McPherson
f754f028dc simplify showcase mode setting in DESCRIPTION 2014-01-06 13:43:02 -08:00
Jonathan McPherson
41b292b45b complete refactoring of raw text output to tags$... methods 2014-01-06 13:19:07 -08:00
Jonathan McPherson
af9be9cae8 use tags functions for writing app info block 2014-01-06 11:03:53 -08:00
Jonathan McPherson
ccfaea64c5 simplify & clean up construction of markdown content 2014-01-06 10:38:05 -08:00
Yihui Xie
a86fc96730 yes, it is weird to select by names instead of values; now the weirdness has gone 2013-12-31 17:03:43 -06:00
Yihui Xie
cf51af17fd news for #340 2013-12-31 16:50:07 -06:00
Yihui Xie
8c1b6a5cf0 update JS tests accordingly
note that getState() no longer includes state.options.selected/checked, which is actually redundant since there is state.value
2013-12-31 16:49:48 -06:00
Yihui Xie
bcecb8cd76 roxygenize 2013-12-31 16:48:17 -06:00
Yihui Xie
557790b0e5 selected refers to values instead of labels/names of choices
added validateSelected() for backward compatibility
2013-12-31 16:48:04 -06:00
Yihui Xie
8eb5a45718 per suggestion of @wch, we do not pass the selected/checked status in the message; the selected values are in message$value, and they will be set via this.setValue(el, data.value) in receiveMessage() in shiny.js
also note that updateSelectInput() is essentially the same as updateCheckboxGroupInput() now, because it does not matter if the attribute name is 'selected' or 'checked'
2013-12-31 15:06:17 -06:00
Yihui Xie
7b64cef73b fixes #176: the problem of choices=NULL also affects selectInput() 2013-12-31 15:06:17 -06:00
Yihui Xie
106203170e pass the selected value(s) to checkbox/radio group 2013-12-31 15:06:17 -06:00
Yihui Xie
174d2bfc11 only do mapply() when length(choices) > 0, otherwise options = list(), and this will lead to an empty checkbox/radio group 2013-12-31 15:06:17 -06:00
Yihui Xie
abda9c7f97 it is not possible to do names(NULL) <- value, so return early when choices is NULL
https://groups.google.com/forum/?pli=1#!topic/shiny-discuss/K7chwrMCvkU
2013-12-31 15:06:17 -06:00
Yihui Xie
8e95260df9 for select input, setValue() with a nonexistent value turns its value to null 2013-12-31 15:05:22 -06:00
Jonathan McPherson
5af1ae1920 reflow comments (and a handful of code lines) to 65 characters 2013-12-30 15:18:21 -08:00
Jonathan McPherson
f0eb9d48c9 show license beneath code 2013-12-30 14:31:45 -08:00
Jonathan McPherson
0ac284009e add Readme.md files to most examples 2013-12-30 13:05:54 -08:00
Winston Chang
fcf963639e Update to Cairo 1.5-5
This version of Cairo properly uses the res argument, so it works with
resolutions higher than 72.
2013-12-27 21:41:34 -06:00
JJ Allaire
ba8c0fb1d5 change name of app start hook to be more consistent with app stop hook 2013-12-26 19:01:45 -05:00
JJ Allaire
08fe74675b update docs on updateTabsetPanel to reflect it's applicablity to navbarPage and navlistPanel 2013-12-25 15:16:52 -05:00
JJ Allaire
f5e7fdf8aa simplify handling of nested menus in tabInputBinding 2013-12-25 15:16:13 -05:00
Joe Cheng
f6e447d049 Merge pull request #349 from rstudio/feature/run-hook
add application run and stop hooks
2013-12-24 09:54:14 -08:00
JJ Allaire
531b21c012 add application run and stop hooks 2013-12-24 10:40:10 -05:00
JJ Allaire
a057456d5a add docs for icon argument to navbarMenu 2013-12-24 09:31:24 -05:00
JJ Allaire
0f043b39f5 add id parameter to navbarPage (support for tab input binding) 2013-12-24 09:12:41 -05:00
Jonathan McPherson
dc0701e21d update DESCRIPTION files and a Readme; tweak spacing 2013-12-23 16:23:33 -08:00
Jonathan McPherson
712f18f4e8 clean up some comments and accidentally introduced whitespace changes 2013-12-23 15:04:05 -08:00
Jonathan McPherson
e0a82b4aaf Merge remote-tracking branch 'origin/master' into feature/showcase-mode 2013-12-23 14:46:48 -08:00
JJ Allaire
a7f238ae0b use correct selector for navbar menu auto-collapse 2013-12-21 17:44:07 -05:00
Yihui Xie
0d99b6de7a Merge pull request #345 from jcheng5/print-html
Nicer printing of HTML tags at console
2013-12-21 11:51:20 -08:00
Joe Cheng
6f627fca96 Minor doc tweak 2013-12-21 11:01:10 -08:00
Joe Cheng
339fbc482b Smarter cursor choosing for absolutePanel 2013-12-21 10:53:23 -08:00
Joe Cheng
72e3ee1d77 Nicer printing of HTML tags at console 2013-12-21 10:26:45 -08:00
Joe Cheng
a9750fb088 Add absolutePanel and fixedPanel (and jquery-ui)
jQueryUI is needed for draggable functionality.
2013-12-20 14:53:11 -08:00
JJ Allaire
d80e3b0824 don't auto-hide when collapased navbar submenu is clicked 2013-12-20 17:06:42 -05:00
Jonathan McPherson
46df7a9ea0 make jshint happy (avoid leaking globals) 2013-12-20 12:23:05 -08:00
Joe Cheng
b851ce49f7 Forgot to roxygenize a previous doc change 2013-12-20 11:54:22 -08:00
Winston Chang
d9afde3e15 Merge pull request #342 from trestletech/master
Unlist dates to properly handle date ranges.
2013-12-19 20:34:43 -08:00
trestletech
b38c57f308 Unlist dates to properly handle date ranges. 2013-12-19 17:58:17 -06:00
Jonathan McPherson
93e7e2e06e set height of code window based on height of surrounding window 2013-12-19 15:08:27 -08:00
Jonathan McPherson
5ac09180a5 don't emit superfluous newline at beginning of .R files 2013-12-19 14:03:07 -08:00
JJ Allaire
3819ca3a62 add descriptions for examples 2013-12-19 16:59:26 -05:00
Jonathan McPherson
00426b4c9b fix incorrect character accounting with newlines 2013-12-19 13:39:36 -08:00
Jonathan McPherson
58d8cefcc0 set sxs mode on load if browser is wide enough 2013-12-19 12:51:08 -08:00
Jonathan McPherson
c8bb122557 hide entire well when app doens't have metadata in sxs mode 2013-12-19 12:21:17 -08:00
Jonathan McPherson
bcef603a36 new layout: remove top bar, show app info by readme 2013-12-19 11:35:27 -08:00
Jonathan McPherson
639b4d392a coerce strings from DESCRIPTION to correct types 2013-12-19 10:18:57 -08:00
Jonathan McPherson
6d5f06a61d initial support for showcase mode from DESCRIPTION (not complete) 2013-12-18 17:06:31 -08:00
Jonathan McPherson
3e00e2ad58 show contents of global.R if it exists 2013-12-18 15:13:11 -08:00
Jonathan McPherson
cad2be5e53 always use tabs to show code; show readme alongside code 2013-12-18 13:41:15 -08:00
Jonathan McPherson
58fe5f263f nicer code tabs in code-alongside mode 2013-12-17 20:18:22 -08:00
Jonathan McPherson
79ec6845f8 use more bootstrap-flavored styles 2013-12-17 16:10:53 -08:00
Jonathan McPherson
0f81ba8307 use minified jquery ui 2013-12-17 15:09:26 -08:00
Jonathan McPherson
a30543b035 use rstudio fork of highlight.js 2013-12-17 14:51:44 -08:00
Jonathan McPherson
5c4473a1d9 use side-by-side code and app instead of a popup window 2013-12-17 14:07:22 -08:00
Jonathan McPherson
7ff47c8c51 use rstudio default highlight colors 2013-12-17 13:52:17 -08:00
Jonathan McPherson
2544e29be3 use show with app / show below buttons to toggle 2013-12-17 13:16:23 -08:00
Jonathan McPherson
d7bf564e8f make initial transition a little smoother 2013-12-17 11:15:11 -08:00
Jonathan McPherson
0f135f881a make code position toggleable 2013-12-17 10:56:40 -08:00
Jonathan McPherson
2f1bb5e1c0 begin restricting code height and scrolling relevant portion into view 2013-12-17 10:23:27 -08:00
Jonathan McPherson
02b5f96eee move from popup window model to side-by-side model 2013-12-17 09:00:27 -08:00
JJ Allaire
3e77871539 move shinyapps gitignore to root 2013-12-16 17:38:57 -05:00
Jonathan McPherson
676affdd03 add new header-free showcase mode (use showcase=2 on query string) 2013-12-16 14:12:13 -08:00
Jonathan McPherson
5caf41c067 Merge remote-tracking branch 'origin/master' into feature/showcase-mode 2013-12-16 13:21:59 -08:00
Jonathan McPherson
58f9e89fab restore javascript markdown formatter 2013-12-16 13:15:11 -08:00
JJ Allaire
8776f0f4a5 Merge branch 'feature/showcase-mode' of github.com:rstudio/shiny into feature/showcase-mode 2013-12-16 15:19:47 -05:00
JJ Allaire
84a8c27926 gitignore for artifacts of deploying to shinyapps 2013-12-16 15:17:13 -05:00
Jonathan McPherson
f061e3486e move showcase-specific css to its own file 2013-12-16 09:52:58 -08:00
Jonathan McPherson
da23995343 make jshint happy 2013-12-16 09:35:31 -08:00
Yihui Xie
4e0a61bd9b Merge pull request #319 from jcheng5/feature/console-reactivity
Features for easier explaining of reactivity
2013-12-16 09:28:14 -08:00
Yihui Xie
d3e2fa5df5 Merge pull request #336 from jcheng5/bugfix/335-singleton-observer
Fix #335: Singleton observer shows up in reactlog
2013-12-16 09:25:50 -08:00
Joe Cheng
00b111c974 Merge remote-tracking branch 'origin/master' into feature/console-reactivity
Conflicts:
	NAMESPACE
	NEWS
2013-12-16 09:25:45 -08:00
Jonathan McPherson
bd265c00a0 add documentation for showcase mode parameter to runApp 2013-12-16 09:25:02 -08:00
Joe Cheng
ef53a63766 Merge pull request #327 from rstudio/feature/bootstrap-layout
fluidPage and fixedPage and related bootstrap layout functions
2013-12-16 09:18:35 -08:00
JJ Allaire
688c7f1a1c improve docs on theme parameter 2013-12-16 12:01:22 -05:00
Winston Chang
2989922253 Bump Cairo to 1.5-4
This is to avoid a bug in 1.5-3, where plots wouldn't appear properly.
2013-12-16 10:36:12 -06:00
JJ Allaire
6f6619a5ab Add type parameter to tabsetPanel to enable the use of pill style tabs 2013-12-16 10:20:34 -05:00
JJ Allaire
1594c228e8 re-roxygenize 2013-12-16 10:18:08 -05:00
JJ Allaire
fb44f52aa9 add navlistPanel function 2013-12-16 10:09:38 -05:00
JJ Allaire
045ead1728 re-roxygenzie 2013-12-16 09:58:31 -05:00
JJ Allaire
4404463e53 tweak news linebreak 2013-12-16 08:27:15 -05:00
JJ Allaire
b79b61c8c8 merge from master
Merge remote-tracking branch 'origin/master' into feature/bootstrap-layout

Conflicts:
	NEWS
	R/bootstrap.R
2013-12-16 08:26:22 -05:00
Joe Cheng
467048a0fc Fix erroneous comments in 03_reactivity 2013-12-15 15:15:16 -08:00
Joe Cheng
2a1edffce3 Fix #335: Singleton observer shows up in reactlog 2013-12-15 01:00:16 -08:00
Joe Cheng
ce833c39d5 setAutoflush refactor for clarity 2013-12-15 00:21:49 -08:00
Joe Cheng
721a74eee6 Fix example 2013-12-14 23:35:32 -08:00
Joe Cheng
8f9f4f894c Incorporate code review feedback from @yihui 2013-12-14 23:35:32 -08:00
Joe Cheng
842765dad0 Features for easier explaining of reactivity
- makeReactiveBinding: Turns a "regular" variable into a reactive.
  No need to use reactiveValues() for simple reactivity.
- setAutoflush (not exported): Causes flushReact() to be called
  each time something is executed at the R console top-level.
- options(shiny.suppressMissingContextError=TRUE): Prevents the
  "Operation not allowed without an active reactive context" error
  when attempting to read a reactive value or expression from the
  console.
2013-12-14 23:35:32 -08:00
Joe Cheng
b23cc47d95 Merge pull request #334 from rstudio/feature/font-awesome
icon function for embedding icons from the font-awesome icon library
2013-12-14 21:47:52 -08:00
JJ Allaire
85baa596d0 remove widths parameter from columnLayout; add width parameter to sidebarPanel and mainPanel 2013-12-14 17:26:08 -05:00
JJ Allaire
e371fff110 update NEWS 2013-12-14 10:17:33 -05:00
JJ Allaire
dffe6b4f39 Merge remote-tracking branch 'origin/master' into feature/font-awesome 2013-12-14 09:46:59 -05:00
JJ Allaire
dbf684f385 merge origin/master 2013-12-14 09:46:37 -05:00
JJ Allaire
7b20fd91ef fix R CMD check documentation errors 2013-12-14 09:44:54 -05:00
JJ Allaire
300c25ded1 re-roxygenize 2013-12-14 09:07:37 -05:00
JJ Allaire
284e814d2a integrate icons into the rest of the ui 2013-12-14 09:02:11 -05:00
Jonathan McPherson
d5cdaddeea use markdown package instead of client-side md renderer 2013-12-13 16:15:10 -08:00
JJ Allaire
8635b395a1 Merge remote-tracking branch 'origin/master' into feature/bootstrap-layout 2013-12-13 17:55:59 -05:00
Jonathan McPherson
c2cf4e72f8 decouple showcase mode from app boot; factor out of shiny.js 2013-12-13 14:46:31 -08:00
Yihui Xie
92def0f71d Merge pull request #332 from jcheng5/bugfix/no-html-class
Fix test breakage due to HTML() missing from rendered output
2013-12-13 14:27:36 -08:00
Joe Cheng
bccae9d71c Fix test breakage due to HTML() missing from rendered output 2013-12-13 14:18:06 -08:00
JJ Allaire
90b6a2f82b add documentation on host parameter to runExample 2013-12-13 15:59:46 -05:00
JJ Allaire
0462df7de2 fix documentation error in sidebarLayout 2013-12-13 15:57:40 -05:00
JJ Allaire
d4b29ab08d initial font-awesome import 2013-12-13 15:56:18 -05:00
JJ Allaire
09f2dfe181 Merge remote-tracking branch 'origin/master' into feature/bootstrap-layout 2013-12-13 15:47:37 -05:00
Yihui Xie
317d013a0b Merge pull request #330 from yihui/travis
Travis CI
2013-12-13 12:41:04 -08:00
JJ Allaire
e26b2dcd43 refer to application layout guide 2013-12-13 14:37:49 -05:00
JJ Allaire
4676dbc740 update link to component layout guide 2013-12-13 14:33:10 -05:00
JJ Allaire
778f869ddb all functions now work with fluid or fixed layouts 2013-12-13 13:57:37 -05:00
JJ Allaire
a7e9b1f76d eliminate columnLayout (just use fluidRow) 2013-12-13 13:40:36 -05:00
JJ Allaire
096e56aaa8 eliminate horizontalPanel and pull left/right functions 2013-12-13 13:30:52 -05:00
Jonathan McPherson
d1bcc557f0 move showcase js to its own file; fix cross-document bug on firefox 2013-12-13 10:20:50 -08:00
JJ Allaire
e041fab319 Merge remote-tracking branch 'origin/master' into feature/bootstrap-layout 2013-12-13 09:38:48 -05:00
JJ Allaire
3394e36325 cross reference component and grid layout guides from help topics 2013-12-13 09:19:02 -05:00
JJ Allaire
a501458e5a Refer to Bootstrap without Twitter preface; link explicitly to v2.3.2 documentation 2013-12-13 08:24:11 -05:00
JJ Allaire
da08eef5ef add title parameter to top level page functions 2013-12-13 08:19:44 -05:00
JJ Allaire
0ea714552a update examples to use sidebarLayout rather than pageWithSidebar 2013-12-13 07:52:47 -05:00
JJ Allaire
8cba584e52 deprecation notices 2013-12-13 06:32:49 -05:00
JJ Allaire
878f07d2cf tweak docs for theme parameter 2013-12-13 06:29:29 -05:00
Yihui Xie
d297de732f ignore travis.yml in .Rbuildignore 2013-12-13 00:52:46 -06:00
Yihui Xie
c41d4d32b9 enable Travis CI
YAML copied from https://github.com/yihui/highr/blob/master/.travis.yml
2013-12-13 00:31:31 -06:00
JJ Allaire
5d34134888 update NEWS for theme parameter 2013-12-12 22:47:16 -05:00
Jonathan McPherson
f968ec4cac fix node cloning on IE browsers 2013-12-12 17:03:21 -08:00
Jonathan McPherson
fdb256a534 fix some animation and margin problems 2013-12-12 16:16:04 -08:00
Jonathan McPherson
62a2b57613 clarify regions of app UI vs. showcase UI 2013-12-12 15:45:39 -08:00
JJ Allaire
90f5ebfa58 add support for specifying an alternative bootstrap theme 2013-12-12 17:56:07 -05:00
Jonathan McPherson
66aecee519 fix highlighting for text points inside <SPAN>s 2013-12-12 14:02:53 -08:00
JJ Allaire
f0c661d6e2 enable shiny applications to opt out of bootstrap responsive css 2013-12-12 16:23:26 -05:00
JJ Allaire
a27f5b4c15 make default arguments of navbar page header and footer NULL 2013-12-12 15:58:00 -05:00
Jonathan McPherson
95b69f0003 initial support for sending source refs for reactives (not wired) 2013-12-12 12:57:04 -08:00
JJ Allaire
6925f0bf7a remove head paramter from page functions
tags$head can just be included inline as one of the elements passed to the function at the top-level
2013-12-12 15:48:35 -05:00
Jonathan McPherson
6c1a9ed83b add showdown dependency 2013-12-12 12:18:57 -08:00
Jonathan McPherson
3ebef79313 refactor showcase outputs from renderPage 2013-12-12 12:16:01 -08:00
Jonathan McPherson
57393806b0 initial support for Readme.md 2013-12-12 11:47:04 -08:00
JJ Allaire
721d8cfa49 enhance docs 2013-12-12 14:28:21 -05:00
JJ Allaire
9e5b68444f add support for menus on navbars (navbarMenu function) 2013-12-12 13:41:32 -05:00
Jonathan McPherson
9f6c619401 initial support for header generated from DESCRIPTION 2013-12-12 10:28:38 -08:00
Yihui Xie
1b47e40a3a Merge pull request #328 from rstudio/feature/rproj-changes
Rproj changes: don't roxygenize; use --as-cran for test
2013-12-12 09:44:58 -08:00
JJ Allaire
3fc14102e5 concatenate duplicate attributes in tag definitions 2013-12-12 08:41:53 -05:00
JJ Allaire
d907992c39 Automatically concatenate multiple class attributes in tag definitions 2013-12-12 08:06:20 -05:00
JJ Allaire
ae2f35c6c5 Rproj changes: don't roxygenize; use --as-cran for test 2013-12-12 06:20:35 -05:00
JJ Allaire
ddd804041d Rd changes for R CMD check 2013-12-12 06:16:51 -05:00
JJ Allaire
2478cbdb6f prevent long line lengths for links to bootstrap docs 2013-12-12 06:08:29 -05:00
JJ Allaire
80e992a9fc allow pullLeft/Right functions to take tags or lists of tags; validate that all inputs are tags 2013-12-12 06:02:31 -05:00
JJ Allaire
e4b8e08e89 use paste0 where appropriate 2013-12-12 05:51:12 -05:00
Jonathan McPherson
6c556b8a72 improve style and behavior of code popout window 2013-12-11 17:38:02 -08:00
Jonathan McPherson
9659c19b23 initial support for code pop-out 2013-12-11 17:03:27 -08:00
Jonathan McPherson
aa6e9d9bf2 find column by sibling nodes 2013-12-11 15:07:30 -08:00
Jonathan McPherson
812f0ac32c refine source ref location (columns still need work) 2013-12-11 14:06:12 -08:00
Jonathan McPherson
296b312950 scaffolding for flashing executing outputs 2013-12-11 13:22:00 -08:00
JJ Allaire
29a06406ea Merge remote-tracking branch 'origin/master' into feature/bootstrap-layout 2013-12-11 15:47:01 -05:00
JJ Allaire
261cb7d3cd fix incorrect ellipses arg in hr function 2013-12-11 15:46:38 -05:00
JJ Allaire
ba5a57ac07 fix columnLayout function 2013-12-11 13:38:50 -05:00
JJ Allaire
c0ebe9d7a1 allow row functions to take a class 2013-12-11 13:07:35 -05:00
JJ Allaire
2b83012786 update roxygen docs for navbarPage fluid argument 2013-12-11 13:04:59 -05:00
Jonathan McPherson
b9761288bd send reactive log information to the client 2013-12-11 09:48:37 -08:00
JJ Allaire
a711e83398 Merge remote-tracking branch 'origin/master' into feature/bootstrap-layout 2013-12-11 12:43:21 -05:00
Yihui Xie
2705385681 Merge pull request #320 from rstudio/feature/layout-cleanup
misc cleanup of new layout functions
2013-12-11 09:11:42 -08:00
JJ Allaire
4b2f3dd070 merge from master
Merge remote-tracking branch 'origin/master' into feature/bootstrap-layout

Conflicts:
	NAMESPACE
	NEWS
2013-12-11 06:05:22 -05:00
JJ Allaire
876acf2839 Merge remote-tracking branch 'origin/master' into feature/layout-cleanup 2013-12-11 06:00:43 -05:00
JJ Allaire
d0446f068c Merge remote-tracking branch 'origin/master' into feature/layout-cleanup 2013-12-11 05:59:02 -05:00
Yihui Xie
a9396d1e2f Merge pull request #324 from rstudio/feature/hr-tag
add hr tag to exported html builder tags
2013-12-10 21:01:28 -08:00
JJ Allaire
e87102e586 update NEWS 2013-12-10 20:41:17 -05:00
JJ Allaire
8b213f8d7c update NEWS 2013-12-10 20:40:21 -05:00
JJ Allaire
9a7dc5ba86 add hr tag to exported html builder tags 2013-12-10 20:20:16 -05:00
JJ Allaire
9acb3f83f8 add fluid parameter to navbarPage to specify fluid vs. fixed layout 2013-12-10 20:04:57 -05:00
JJ Allaire
1c676211ee more revisions to layout functions -- go back to page level constructs for fixed and fluid 2013-12-10 16:15:17 -05:00
Jonathan McPherson
89728164eb highlight code with highlight.js 2013-12-10 12:11:40 -08:00
Jonathan McPherson
d0c4093f5a use built-in parseQueryString 2013-12-10 10:46:03 -08:00
Jonathan McPherson
d7f680fb19 show ui.R and server.R files in showcase mode 2013-12-10 10:20:50 -08:00
JJ Allaire
48279e060c add validation of layout function inputs 2013-12-10 12:57:56 -05:00
Jonathan McPherson
10dd0d07dc showcase mode stub controlled by showcase=1 parameter 2013-12-10 09:50:51 -08:00
JJ Allaire
d82dc4cf77 introduce more layout functions 2013-12-10 12:02:59 -05:00
JJ Allaire
2b9553e4da refactor functions to use fixed and fluid explicitly and to introduce the notion of "layout" functions 2013-12-10 11:35:56 -05:00
Joe Cheng
ac112ea287 Race condition where clientData$singletons can be NULL
Reproduced in Shiny Server load testing.

Code reviewed by @trestletech
2013-12-09 15:51:45 -08:00
JJ Allaire
4f6b099615 move page functions to the top of the bootstrap-layout file 2013-12-09 16:43:55 -05:00
JJ Allaire
d4dcb162d0 functions for creating lower-level bootstrap layouts 2013-12-09 14:35:49 -05:00
Yihui Xie
46054f513b fixes #314: the data passed to htmlOutputBinding could be null 2013-12-08 17:55:49 -06:00
JJ Allaire
261f67df50 update NAMESPACE For removed panelWithSidebar 2013-12-08 09:14:36 -05:00
JJ Allaire
22f9b2affe rename tabsPosition to position 2013-12-08 09:10:50 -05:00
JJ Allaire
06c392c066 remove panelWithSidebar (this scenario will be handled by more composable top-level pages) 2013-12-08 09:10:28 -05:00
JJ Allaire
3d67b3bc17 Merge branch 'feature/remove-tab-condition' into feature/layout-cleanup 2013-12-08 09:06:47 -05:00
JJ Allaire
6cefab5d8a Merge branch 'feature/navbar-header-footer' into feature/layout-cleanup 2013-12-08 09:06:35 -05:00
JJ Allaire
cc261de37b remove condition attribute from tabPanel
the tab content visibility needs to be the union of data-display-if and whether the tab is active (the currenty implementation makes it always visible when data-display-if evaluates to true)
2013-12-07 17:16:02 -05:00
JJ Allaire
20712641a7 re-roxygenize for tabsetPanel position argument 2013-12-07 17:09:53 -05:00
JJ Allaire
e4d0b16fd5 add header and footer arguments to navbarPage 2013-12-07 17:09:26 -05:00
JJ Allaire
f8c25791e9 Merge pull request #318 from rstudio/feature/tabs-position
Add position parameter to tabsetPanel
2013-12-06 12:31:50 -08:00
JJ Allaire
704aa433d4 use match.arg for tabsPosition 2013-12-06 15:30:23 -05:00
Joe Cheng
3bd1003164 Merge pull request #316 from rstudio/feature/conditional-tabs
conditional expression to determine visibility of tabPanel
2013-12-06 11:21:58 -08:00
JJ Allaire
8dd55d7506 always assign data-display-if (it will be dropped if it's NULL) 2013-12-06 13:04:56 -06:00
Joe Cheng
6252d778c1 Merge pull request #317 from rstudio/feature/head-param
add optional head parameter to top-level page functions
2013-12-06 10:58:26 -08:00
Joe Cheng
942248b9e6 Merge pull request #315 from rstudio/feature/navbar-page
navbarPage and panelWithSidebar
2013-12-06 10:51:07 -08:00
Winston Chang
4793449105 Add example for actionButton 2013-12-06 12:13:31 -06:00
JJ Allaire
428e3bc0fc forward head parameter in pageWithSidebar 2013-12-06 12:09:35 -06:00
Winston Chang
bf2c80cfcf Improvements to invalidateLater docs 2013-12-06 12:09:23 -06:00
JJ Allaire
06b0685a57 change name of position parameter to tabsPosition 2013-12-06 11:33:49 -06:00
JJ Allaire
231ea25968 Add position paramter to tabsetPanel to enable positioning of tabs above, below, left, or right of tab content 2013-12-06 10:34:04 -06:00
JJ Allaire
8658eeddb2 update NEWS 2013-12-06 09:10:38 -06:00
JJ Allaire
d0769eed97 add optional head parameter to top-level page functions 2013-12-06 08:56:20 -06:00
JJ Allaire
b1fcd1f7c8 conditional expression to determine visibility of tabPanel 2013-12-06 08:12:26 -06:00
JJ Allaire
db1259b3e0 docs for collapsable and re-roxygenize 2013-12-05 10:31:03 -06:00
JJ Allaire
1a5f42b753 auto collapse navbar menu on click 2013-12-05 10:12:39 -06:00
JJ Allaire
75d061a7fa support optional collablable navbar 2013-12-05 09:17:57 -06:00
JJ Allaire
9fb4c4140b navbarPage and panelWithSidebar 2013-12-05 07:09:46 -05:00
JJ Allaire
0306877fb9 re-roxygenize for host parameter 2013-12-04 13:07:06 -05:00
Winston Chang
86e3b05a3f Merge pull request #233 from trestletech/input-registry
Create a user-extensible registry of custom Shiny Input handlers.
2013-12-03 14:19:05 -08:00
trestletech
a4e8907c95 Merged rstudio/master into branch. 2013-12-03 15:15:14 -06:00
Yihui Xie
916ad6535a fixes #299: RJSONIO is unable to convert a matrix of 0 row to [], in which case we have to use an empty list() instead
toJSON(list(x = matrix(nrow = 0, ncol = 3))) gives '{\n "x":  \n}', which is an invalid JSON expression
2013-12-03 15:03:39 -06:00
Yihui Xie
c129309937 Merge pull request #310 from yihui/master
closes #277: implement actionButton.setValue()
2013-12-03 12:55:46 -08:00
trestletech
0088e9ae77 Preface shiny input classes with shiny. Refine tests to use S3 dispatch. 2013-11-30 15:19:21 -06:00
Yihui Xie
79806b5ad5 closes #277: implement actionButton.setValue() 2013-11-26 23:51:35 -06:00
Winston Chang
7d59fbfc36 Merge pull request #302 from wch/jshint
Fixes to make JSHint happy
2013-11-22 12:11:07 -08:00
Winston Chang
e645bdf249 Add jshint options to suppress warnings 2013-11-22 13:51:52 -06:00
Winston Chang
0bedf26849 Check for own properties 2013-11-22 13:36:18 -06:00
Winston Chang
a153c5b4ce Change function defs to vars
This makes the scoping clearer.
2013-11-22 13:32:54 -06:00
Winston Chang
44f1f3e9ae Fixes for jshint 2013-11-21 17:07:47 -06:00
Winston Chang
8c82fa86c6 Update NEWS 2013-11-21 16:42:56 -06:00
Winston Chang
d4da934d6a Merge branch 'renderui-head-singleton'
Conflicts:
	NEWS
2013-11-21 16:42:42 -06:00
Winston Chang
56cc664c26 Use === 2013-11-21 16:37:16 -06:00
Joe Cheng
eaa0bdfc62 Merge pull request #278 from yihui/changeset/source
use sys.source() and keep.source=TRUE
2013-11-21 13:34:08 -08:00
Yihui Xie
c538e9c6d4 use globalenv() instead of .Globalenv; remove local() 2013-11-20 18:00:24 -06:00
Winston Chang
54b9af0299 Merge branch 'localhost-only'
Conflicts:
	NEWS
2013-11-20 13:54:47 -06:00
Winston Chang
c7d5b9211c Merge pull request #271 from wch/bootstrap
Update to Bootstrap 2.3.2 and jQuery 1.10.2
2013-11-19 20:15:20 -08:00
Winston Chang
7ca22a8718 Add updated version of jslider
This adds compatibility with jQuery 1.9+
2013-11-19 21:47:39 -06:00
trestletech
4e37b32976 Enumerate function variables, setup Roxygen to pass R CMD CHECK, added tests. 2013-11-19 20:46:51 -06:00
Winston Chang
9725b23db1 Update NEWS 2013-11-19 14:36:21 -06:00
Winston Chang
2e60f2b2ce Update to jQuery 1.10.2 2013-11-19 14:35:53 -06:00
Winston Chang
004776a522 Fix dateinput docs for pt-BR language 2013-11-19 11:19:12 -06:00
Joe Cheng
92fa1dde79 Fix #21: singleton and tags$head are not really compatible with reactiveUI
This commit fixes two problems:

- tags$head content was not properly hoisted into the head
  of the document when UI was reactively rendered
- singletons were not respected in renderUI

This makes it possible for input/output components that rely
on JavaScript libraries to simply put their script/style
dependencies in their input/output methods. This is contrary
to previous versions of Shiny where that approach would work
unless the component only appeared in renderUI/uiOutput and
not as part of the initial page render.
2013-11-09 15:11:22 -08:00
Joe Cheng
464821c4e2 Only allow access via localhost by default
This can be overridden via the "shiny.host" option or by explicitly
passing the host parameter to runApp/runExample.
2013-11-08 23:26:59 -08:00
Joe Cheng
e95483236a Merge pull request #295 from wch/quiet
Add quiet option to runApp
2013-11-08 22:03:42 -08:00
Winston Chang
a9b97a85ad Add quiet option to runApp 2013-11-07 11:26:27 -06:00
Yihui Xie
6170befc90 Merge pull request #289 from wch/methods
Move methods package to Depends
2013-11-01 12:30:39 -07:00
Winston Chang
5ecb85cb6d Bump version to .99 for development 2013-10-30 10:34:50 -05:00
Winston Chang
d2fc04f45d Merge branch 'v0.8.0-rc' 2013-10-30 10:33:27 -05:00
Joe Cheng
fb4da933d4 Update version number in NEWS 2013-10-29 12:31:58 -07:00
Yihui Xie
7483900db2 fixes #288: moving shinyCallingHandlers() to a lower-level so that the shiny.error handler can be applied to observe() and isolate() as well 2013-10-28 23:17:02 -05:00
Winston Chang
9f78dbf200 Move methods package to Depends 2013-10-26 12:05:12 -05:00
Yihui Xie
ef9b9bdd6d prepare the v0.8 release in the RC branch 2013-10-24 23:48:48 -05:00
Yihui Xie
1937aa43ba Ah, brain poisoned by R's return() syntax; check if data is empty, then check data.colnames to make sure column names are passed in 2013-10-23 21:26:47 -05:00
Yihui Xie
293ea66784 fixes #286: if the data passed to renderDataTable() does not have dim==2, return an empty object 2013-10-23 21:14:18 -05:00
Yihui Xie
e98d8f4ced Merge pull request #284 from jcheng5/shiny-server-creds
Make Shiny Server credentials available on session object
2013-10-22 11:35:20 -07:00
Joe Cheng
418d2afb2a Make Shiny Server credentials available on session object 2013-10-22 10:42:29 -07:00
Yihui Xie
a4c1a6187f roxygenize and sync doc 2013-10-22 12:33:07 -05:00
Yihui Xie
123ca34040 tweak the roxygen doc for installExprFunction() (otherwise the second paragraph is treated as \description{}) 2013-10-22 12:33:07 -05:00
Joe Cheng
6b3224116c Merge pull request #279 from yihui/datatables
DataTables
2013-10-22 09:43:13 -07:00
Yihui Xie
635e0c9788 news for shiny v0.8 2013-10-22 10:40:29 -05:00
Yihui Xie
dd33a0e0ec the error object may not be interesting at all; just call the handler without arguments
this makes it easier to set options(shiny.error = browser/recover/traceback/...), otherwise will have to do options(shiny.error = function(e) traceback()), which seems awkward
2013-10-22 10:33:01 -05:00
Yihui Xie
191deeaba6 a hack to remove the scrollbars in tab panels 2013-10-22 02:07:06 -05:00
Yihui Xie
245072f7a2 make sure colnames is an array, even when there is only one column in the data 2013-10-22 02:07:06 -05:00
Yihui Xie
6b858512b6 must empty the data table first 2013-10-22 02:07:06 -05:00
Yihui Xie
b857a01c30 save $(el) in $el 2013-10-22 02:07:06 -05:00
Yihui Xie
94c9a3e05b should not have assigned installExprFunction() to func 2013-10-22 02:07:06 -05:00
Yihui Xie
8928d2c488 use the new installExprFunction() instead of exprToFunction() 2013-10-22 02:07:06 -05:00
Yihui Xie
25bd5654aa display 25 rows by default, again per suggestion of JJ 2013-10-22 02:07:06 -05:00
Yihui Xie
83d5b96adf no CSS classes for sorted columns, per suggestion of JJ 2013-10-22 02:07:06 -05:00
Yihui Xie
7eb90c5718 roxygenize 2013-10-22 02:07:06 -05:00
Yihui Xie
4b1af75724 debouncing is done single-handedly, thanks to Joe's smart debounce() function 2013-10-22 02:07:06 -05:00
Yihui Xie
8d07ab6527 roxygenize 2013-10-22 02:07:06 -05:00
Yihui Xie
ce4ea7e7a9 allow users to pass initialization options to datatables 2013-10-22 02:07:06 -05:00
Yihui Xie
50ab5e7517 BSD license for DataTables 2013-10-22 02:07:06 -05:00
Yihui Xie
431c1d7f66 css for the processing indicator 2013-10-22 02:07:06 -05:00
Yihui Xie
a55090dc2f the searching should use intersection instead of union 2013-10-22 02:07:06 -05:00
Yihui Xie
d76cdb73b0 remove the ColumnFilter plugin; it is too heavy, and I just added the <input> by myself and implemented searching by individual columns 2013-10-22 02:07:05 -05:00
Yihui Xie
2594664330 use the nicer bootstrap style 2013-10-22 02:07:05 -05:00
Yihui Xie
f9ed075db6 write a datatable output binding; the column names and action url are passed from renderDataTable() to the output binding 2013-10-22 02:07:05 -05:00
Yihui Xie
099ced4f94 implement searching by columns 2013-10-22 02:07:05 -05:00
Yihui Xie
13d2513930 index from 0, sigh 2013-10-22 02:07:05 -05:00
Yihui Xie
2211b1c65e now we can sort multiple columns: press Shift and click the column headers 2013-10-22 02:07:05 -05:00
Yihui Xie
1fd37ca2b2 implement sorting; the very basic features are there now, but this still needs a lot of improvement in terms of details 2013-10-22 02:07:05 -05:00
Yihui Xie
7070e3748d disable default sorting 2013-10-22 02:07:05 -05:00
Yihui Xie
dfaef908c2 make sure the data has two dimensions 2013-10-22 02:07:05 -05:00
Yihui Xie
67540c763b a simple implementation of global searching 2013-10-22 02:07:05 -05:00
Yihui Xie
14269bd4d9 document renderDataTable() and dataTableOutput() 2013-10-22 02:07:05 -05:00
Yihui Xie
131663032c the ... argument is not really used 2013-10-22 02:07:05 -05:00
Yihui Xie
8ac71165e9 add dataTableOutput() and renderDataTable() for the DataTables library
not yet done, but at least paging is working now
2013-10-22 02:07:05 -05:00
Yihui Xie
346758d3f0 white spaces 2013-10-21 21:40:28 -05:00
trestletech
d3e7f130fb Parse incoming NULLs as NA. 2013-10-21 21:33:25 -05:00
Yihui Xie
aef8837b5d add .csv to fileInput() to make it consistent with the tutorial (#280) 2013-10-21 21:25:42 -05:00
Yihui Xie
dc0832adba should pass a session object to invalidateLater() 2013-10-21 21:20:41 -05:00
trestletech
c0cd269322 Revert "Customize dispatch for NULL objects."
This reverts commit f4ada70e56.
2013-10-21 20:43:02 -05:00
Joe Cheng
0ad3ff655e Merge remote-tracking branch 'origin/pr/276'
Conflicts:
	R/shiny.R
2013-10-21 10:11:05 -07:00
Yihui Xie
ef45a62cc9 Merge pull request #282 from rstudio/feature/httpuv-version
bump the required version of httpuv to v1.2
2013-10-20 09:56:17 -07:00
JJ Allaire
b79abbdea9 bump the required version of httpuv to v1.2
this is to pull the changes to httpuv that enable shiny applications to run inside the rstudio viewer pane
2013-10-20 06:34:52 -04:00
Yihui Xie
a9e4ce005d closes #238: use keep.source() for sys.source() 2013-10-18 22:38:32 -05:00
Yihui Xie
987f2b2a55 closes #236: use sys.source(envir=) instead of source(local=) 2013-10-18 22:19:25 -05:00
Yihui Xie
930e2d1d9d closes #272: the argument ws_env was not used anywhere 2013-10-18 22:01:17 -05:00
trestletech
f4ada70e56 Customize dispatch for NULL objects.
Don't provide class for input objects based on `type` field. Provide real NULLs to dispatched functions rather than empty lists.
2013-10-18 17:27:28 -05:00
trestletech
97e658709d Added S3-dispatched input parsers. 2013-10-18 17:20:24 -05:00
Joe Cheng
ec2992cd2d Merge pull request #264 from rstudio/feature/debug-hooks
Export installExprFunction and add supporting documentation
2013-10-17 09:44:03 -07:00
Joe Cheng
619208565b Merge pull request #273 from yihui/feature/callinghandlers
use withCallingHandlers() so that users can do error handling like recover()
2013-10-17 09:39:01 -07:00
Joe Cheng
dcd689d2ea Don't clear timers when runApp returns
The lifetimes of reactive expressions and observers can span multiple
runApp calls, so timers should as well.
2013-10-16 15:34:25 -07:00
Yihui Xie
e94de15f83 well, we still have to use do.call($) on .self; closes #274
Winston reported the issue at https://stat.ethz.ch/pipermail/r-devel/2013-October/067744.html

partially reverted 86d61e0b44
2013-10-16 15:42:36 -05:00
Yihui Xie
6af7de51a5 another attempt to close #249, using withCallingHandlers() instead of modifying tryCatch()
also closes #217 if everyone agrees with this approach
2013-10-16 00:57:54 -05:00
Winston Chang
559c6722ff Update NEWS 2013-10-15 15:24:02 -05:00
Winston Chang
aab2cce978 Update to Bootstrap 2.3.2 2013-10-15 12:13:34 -05:00
Joe Cheng
f4a4af0fa4 Merge pull request #265 from yihui/bug/offset
a more reliable solution for e.offsetX/Y in Firefox
2013-10-14 11:02:20 -07:00
Joe Cheng
6934838974 Merge pull request #268 from rstudio/feature/parent-notify-disconnected
send disconnected message to parent frame when running on localhost
2013-10-11 07:51:34 -07:00
JJ Allaire
1aadd25cb5 notify iframe parent of disconnect when on the same domain 2013-10-10 06:20:26 -04:00
Winston Chang
0caf944668 Fix typo 2013-10-09 16:04:14 -05:00
Jonathan McPherson
6452f62b88 use a check hint (globalVariables()) in favor of modifying code in renderImage 2013-10-08 23:24:27 -07:00
Yihui Xie
e061dfd808 roxygenize 2013-10-08 23:42:19 -05:00
Yihui Xie
4da53ef219 a better solution for e.offsetX/Y in Firefox based on http://stackoverflow.com/q/12704686/559676
which fixes the bug reported by Greg D: https://groups.google.com/forum/#!topic/shiny-discuss/E6oYvyvx0oU
2013-10-08 23:34:34 -05:00
Jonathan McPherson
347e44f04d look up function by name (for R CMD check --as-cran) 2013-10-08 15:29:35 -07:00
Joe Cheng
8997fa7242 Merge pull request #252 from jcheng5/random-ports2
Try up to 20 random ports if necessary
2013-10-08 13:58:17 -07:00
JJ Allaire
19ba6efb82 allow a custom function for the launch.browser parameter 2013-10-08 13:56:14 -07:00
Jonathan McPherson
d10cbc9984 export and add docs for installExprFunction 2013-10-08 10:36:31 -07:00
Jonathan McPherson
6c7d9ded00 simplify syntax for creating new debuggable expressions 2013-10-07 11:11:59 -07:00
Yihui Xie
6d04e89d7d Merge pull request #262 from yihui/r-check
synchronize doc
2013-10-06 15:50:01 -07:00
Yihui Xie
2beb24147d roxygenize 2013-10-06 17:47:09 -05:00
Yihui Xie
16c5f4e377 no need to expose the documentation to users; expose registerShinyDebugHook to R so that R CMD check does not complain
per discussion in #258, and closes #259
2013-10-06 17:46:45 -05:00
Joe Cheng
03a6f1753c Merge pull request #258 from rstudio/feature/debug-hooks
Add debug hook (when present) for functions generated by exprToFunction
2013-10-02 20:06:46 -07:00
Jonathan McPherson
9fb61d8446 tag Shiny server function for special debug treatment if needed 2013-10-02 12:27:44 -07:00
Jonathan McPherson
bc3322d3c9 allow debugging Shiny server function itself 2013-10-02 10:47:38 -07:00
Jonathan McPherson
06c7bf7514 invoke debug hook function if present after instantiating app functions 2013-10-02 08:53:45 -07:00
Yihui Xie
4c89a000e4 Merge pull request #257 from yihui/trycatch
rewrite some instances of do.call()
2013-10-01 23:33:44 -07:00
Yihui Xie
86d61e0b44 we do not really need do.call() in these cases 2013-10-02 01:30:31 -05:00
Joe Cheng
6407390d72 Try up to 20 random ports if necessary 2013-09-30 16:13:46 -07:00
Yihui Xie
648120cabf Merge pull request #243 from jcheng5/master
Conditional panel expressions were broken for typed inputs
2013-09-28 21:30:42 -07:00
Joe Cheng
ce5b3f290a Merge pull request #245 from rstudio/feature/random-port
choose a random port for runApp
2013-09-27 12:36:49 -07:00
JJ Allaire
5308ca1806 use .globals rather than .runContext 2013-09-27 15:36:02 -04:00
JJ Allaire
6df6d408d2 choose a random port for runApp and continue to use it for the duration of the session unless explicitly overridden 2013-09-27 07:59:44 -04:00
Joe Cheng
b60d6ccdd8 Conditional panel expressions were broken for typed inputs 2013-09-26 15:31:14 -07:00
Joe Cheng
de01c9685e Merge pull request #235 from crtahlin/patch-2
Typo fix.
2013-09-26 10:37:56 -07:00
Joe Cheng
31d2ecc9fd Merge pull request #234 from crtahlin/patch-1
Typo fix.
2013-09-26 10:37:31 -07:00
Yihui Xie
2f8502aec6 save coordmap in $el.data() so it can be dynamically retrieved
6161eaa was an inappropriate fix

(jcheng: cherry-picked from @yihui/master)
2013-09-26 10:33:37 -07:00
Joe Cheng
d377b04dad Make websocket path relative to Shiny page path
This is necessary for proxy situations that don't override the
Shiny.createSocket function (so, not including Shiny Server,
but more like Nginx, HAProxy, and a future version of RStudio
Server).

Without the path being preserved, it's impossible for these
proxies to know that the URL should be forwarded to the host
and port that belongs to Shiny.
2013-09-19 22:53:11 -07:00
crtahlin
40cc78ae1e Typo fix. 2013-09-14 23:12:45 +02:00
crtahlin
268f1e8472 Typo fix. 2013-09-14 22:54:20 +02:00
Winston Chang
004b7c782d Add mailing list information to README 2013-09-11 11:09:18 -05:00
Winston Chang
33b293f0aa Merge pull request #226 from crtahlin/patch-2
Fixed typo.
2013-09-05 17:53:51 -07:00
crtahlin
ad584a98ad Fixed typo. 2013-09-05 17:25:27 +02:00
Jeff Allen
e2509eddb2 Merge pull request #225 from crtahlin/patch-1
Fixed typo.
2013-09-05 08:09:03 -07:00
crtahlin
b9f72d0e78 Fixed typo. 2013-09-05 16:35:04 +02:00
Joe Cheng
c839bb2db3 Merge pull request #224 from yihui/patch-1
websockets has been changed to httpuv
2013-09-04 10:38:04 -07:00
Yihui Xie
30161369a8 websockets has been changed to httpuv 2013-09-03 17:24:05 -05:00
Winston Chang
c65aa9732e Bump version to 0.7.0.99 for development 2013-08-29 11:44:30 -05:00
Joe Cheng
bc72b8fd1c Merge pull request #214 from hadley/doc-tweaks
Doc tweaks
2013-08-27 16:50:00 -07:00
Winston Chang
f089531bd1 Put man-roxygen in .Rbuildignore 2013-08-27 10:08:03 -05:00
Winston Chang
8d8ea53804 Fixes to imports for R-devel 2013-08-26 14:19:50 -05:00
Winston Chang
89e405e927 Bump version to 0.7.0 2013-08-26 12:03:02 -05:00
Joe Cheng
ca984a6630 Implement shiny.sharedSecret option 2013-08-25 22:20:38 -07:00
Joe Cheng
fa39a55eca Wow, IE10 is *really* picky about websocket URLs 2013-08-23 15:42:19 -07:00
Joe Cheng
c3a1ba2f2d Make websocket URL work with IE10
See https://github.com/einaros/ws/issues/131#issuecomment-15715373
2013-08-23 15:38:12 -07:00
Joe Cheng
86e291f250 Add docs for showReactLog. Un-export writeReactLog. 2013-08-23 13:11:04 -07:00
Jeff Allen
dd1d4439a9 Merge pull request #218 from wch/fix-log
Cleanups to reactive logging code for R CMD check
2013-08-23 12:16:23 -07:00
Joe Cheng
cbfde18f8c More updates to NEWS 2013-08-23 12:03:11 -07:00
Winston Chang
e2c2e23d2a Cleanups to reactive logging code for R CMD check
* Fix 'env' partial argument match for get().
* Fix unbound variable access of .shiny__stdout.
* Restructure if statement so test is only done once.
2013-08-23 12:16:18 -05:00
Winston Chang
40cc5d5242 Doc fixes for R CMD check 2013-08-23 12:07:34 -05:00
Winston Chang
9765194ace Bump httpuv version dependency to 1.1.0 2013-08-23 10:16:47 -05:00
Winston Chang
628465e6b5 Update NEWS 2013-08-23 10:16:12 -05:00
Winston Chang
58706df120 Update sliderInput docs 2013-08-23 10:16:05 -05:00
Joe Cheng
b19225c747 Don't send websocket subprotocol
Some time recently, Google Chrome started actually caring what the
client sends for this and what the server replies with. httpuv
doesn't currently have any logic for subprotocol selection, so
it always replies with no Sec-WebSocket-Protocol header, which
now Google Chrome reacts to by closing the websocket connection.

This problem goes away if we just don't send a subprotocol at all.
2013-08-23 02:15:54 -07:00
Joe Cheng
c304889e61 Merge pull request #208 from trestletech/master
Add reactive timing logging, if the necessary variables are available.
2013-08-22 13:55:11 -07:00
trestletech
05a9204678 Added timestamp to reactive log. 2013-08-22 11:20:26 -05:00
hadley
ed8537bb0b Redue duplication in docs betwee date/dateRange 2013-08-14 13:37:14 -05:00
hadley
6a9ae10fcf Add cross-references between input types 2013-08-14 13:33:44 -05:00
hadley
05358904bf Re-document 2013-08-14 13:31:16 -05:00
hadley wickham
1a6901c3e3 Document range slider 2013-08-14 13:25:42 -05:00
Winston Chang
7aaba8244b Add is.reactivevalues function 2013-08-05 14:02:50 -05:00
Winston Chang
8c45dcde88 Merge pull request #205 from hadley/master
Class output of reactive.
2013-08-05 12:02:14 -07:00
Winston Chang
6c155b04b2 Merge pull request #197 from wch/fix-style
Add compatibility wrapper for getComputedStyle in IE8
2013-07-27 17:43:01 -07:00
Winston Chang
cd8ad9a2ec Add compatibility wrapper for getComputedStyle in IE8 2013-07-27 19:41:56 -05:00
hadley
a5db7d0246 Class output of reactive.
Also add print method and test
2013-07-27 11:06:35 -05:00
trestletech
b84b467b96 Added logging of start/stop flushing of reactives using a param provided via HTTP headers. 2013-07-24 17:40:24 -04:00
trestletech
0812aaac88 Merge remote-tracking branch 'rstudio/master' 2013-07-24 08:59:34 -04:00
Joe Cheng
194d2f911e Changes to public-facing session object
- Change from list to environment. This enables the next feature:
- Make $request a promise. websocket$request breaks on some (earlier?) versions
  of httpuv. I'm not sure why this is but in the few hours since I submitted
  the websocket$request change we've had a number of complaints. This way the
  error only occurs if the app actually asks for session$request.
- Make the private session object accessible via `.impl`. Obviously any data or
  methods on the private session object are unsupported but they are there if
  you are desperate and don't mind possible future breakage.
2013-07-23 15:39:27 -07:00
Joe Cheng
e360b36b8a Make WS request available on session object 2013-07-22 15:15:27 -07:00
trestletech
b6f66dd287 Moved print out so we can put it where it belongs. 2013-07-16 08:01:22 -07:00
trestletech
0a4bb48cd3 Added output of process ID on app start. 2013-07-15 14:26:25 -07:00
Joe Cheng
15d62d4a91 Add instructions for installing from GitHub 2013-07-12 01:32:49 +02:00
Joe Cheng
5b13c44ef9 Fix isolate return value bug (issue #200) 2013-07-12 01:30:07 +02:00
Joe Cheng
0a4250f3b4 Merge pull request #193 from jcheng5/reactlog
React log
2013-07-09 00:58:53 -07:00
Joe Cheng
f79223ed58 Merge remote-tracking branch 'origin/master' into reactlog 2013-07-07 01:20:59 -07:00
Joe Cheng
2d28218a2a Allow Cmd+F3 to launch reactlog 2013-07-07 01:20:40 -07:00
Joe Cheng
35974f2ee1 Firefox scrubbing fix 2013-07-06 23:13:25 -07:00
Joe Cheng
1f73323fb9 reactlog: Support arbitrary temporal movement 2013-07-06 23:06:38 -07:00
Joe Cheng
a3d0736eec Use more obscure keyboard shortcut for reactlog 2013-07-06 18:27:10 -07:00
Joe Cheng
4bdd486c00 reactlog: Firefox compatibility; visual tweaks 2013-07-06 18:22:40 -07:00
Joe Cheng
c3895c9bd7 Configurable hover delay type (debounce/throttle) 2013-07-05 17:29:57 -07:00
Joe Cheng
e9ddd89b32 Simpler math 2013-07-05 15:08:42 -07:00
Joe Cheng
88a8f2d609 Fix locator Retina compatibility. Again.
Was working locally on Macs but not on spark.rstudio.com accessed via rMBP.
2013-07-05 13:52:56 -07:00
Joe Cheng
a5dc5c89e8 Firefox locator compat 2013-07-05 12:30:14 -07:00
Joe Cheng
3a15a35137 Merge pull request #192 from jcheng5/flush-callbacks
Add session$onFlush and session$onFlushed
2013-07-05 02:10:02 -07:00
Joe Cheng
b644640804 Add session$onFlush and session$onFlushed 2013-07-05 02:07:51 -07:00
Joe Cheng
aaa4f66671 Merge pull request #183 from jcheng5/plot-mouse-events
Click and hover on static plots. Also, fix retina compatibility and make hover delay configurable
2013-07-04 23:43:54 -07:00
Joe Cheng
07e021199e Use crosshair cursor when plot supports hover/click 2013-07-04 23:42:44 -07:00
Joe Cheng
6b2ca7dc80 Merge pull request #182 from jcheng5/reactive-poll
Implement reactivePoll and reactiveFileReader
2013-07-04 23:31:16 -07:00
Joe Cheng
091d62803e Merge pull request #191 from trestletech/master
Restrict the number of observations to a valid, positive number.
2013-07-04 12:15:57 -07:00
trestletech
547999bae0 Restrict the number of observations to a valid, positive number. 2013-07-03 23:06:42 -05:00
Joe Cheng
99013f7998 Launch reactlog from Shiny app with F3 2013-07-03 12:17:36 -07:00
Joe Cheng
fc396800db reactlog: Automatically run first step 2013-07-03 08:56:28 -07:00
Joe Cheng
6d03ae57ac reactlog: Show value changes 2013-07-03 00:05:28 -07:00
Joe Cheng
4a0aa57355 reactlog node shapes, visible labels 2013-07-02 17:48:09 -07:00
Joe Cheng
7db737494c Reverse reactlog arrow orientation 2013-07-02 13:21:39 -07:00
Joe Cheng
b285501c44 reactlog code cleanup 2013-07-02 08:38:24 -07:00
Joe Cheng
2f9b29994f Add showReactLog function 2013-07-02 03:17:30 -07:00
Joe Cheng
917434cb6b Introduce shiny.reactlog function 2013-07-02 03:03:29 -07:00
Joe Cheng
28a52bb658 More visual improvements to reactlog 2013-07-02 02:59:37 -07:00
Joe Cheng
82bc19374c Improve appearance of reactlog 2013-07-02 02:12:07 -07:00
Joe Cheng
0b23f30bb7 Work in progress 2013-07-02 01:29:33 -07:00
Joe Cheng
64a62d7aed Add doc for workerId param 2013-06-28 13:55:45 -07:00
Joe Cheng
de31cf8e7d Merge pull request #175 from trestletech/master
Add workerID to upload, download, and file URLs.
2013-06-28 13:52:38 -07:00
Winston Chang
3484f9afb3 Merge pull request #179 from wch/faster-tags
Faster tags
2013-06-25 09:57:34 -07:00
Winston Chang
81df0ff390 Fix typo 2013-06-25 11:40:54 -05:00
Winston Chang
d403ec7399 Make hover delay configurable 2013-06-24 16:39:04 -05:00
Winston Chang
6ac77835df Fix Retina compatibility (revert b113119) 2013-06-24 16:31:43 -05:00
Joe Cheng
b113119a9a Retina display compatibility 2013-06-21 21:38:23 -07:00
Joe Cheng
b713057614 Implement click and hover events on static plots
plotOutput now takes clickId and hoverId params that tell Shiny
where to send click and hover events for that plot. The server.R
file can listen on input$<clickId> and/or input$<hoverId>. In
both cases, the resulting value will have numeric x and y elements
that indicate the mouse position in user coordinates. In the case
of hover events, it's also possible to have a NULL value which
means the mouse is not currently hovering over the plot.
2013-06-21 16:58:43 -07:00
Winston Chang
4268570166 Add tests for escaping in tags 2013-06-20 14:13:11 -05:00
Winston Chang
ead508c0d0 Preserve attributes in child tags 2013-06-20 12:16:51 -05:00
Joe Cheng
f8e1be8565 Update shiny-package 2013-06-19 13:09:48 -07:00
Winston Chang
360f1af32f Export tagSetChildren and tagAppendChildren 2013-06-19 15:01:45 -05:00
Joe Cheng
d897df6a30 Implement reactivePoll and reactiveFileReader 2013-06-19 09:16:04 -07:00
Winston Chang
ba4f3a1553 Speed up input update functions 2013-06-19 00:34:57 -05:00
Winston Chang
6ba9534da4 In tag functions, drop NULL attributes 2013-06-19 00:25:46 -05:00
Winston Chang
c16ef96754 Don't use named list items for selectInput and radioButtons
The names aren't used anyway, and this matches previous behavior (Shiny 0.6.0)
2013-06-18 23:53:30 -05:00
Winston Chang
e728491aa2 Refactor checkboxGroupInput 2013-06-18 23:52:41 -05:00
Winston Chang
ce356fa266 Fix handling of empty tags 2013-06-18 23:52:13 -05:00
Winston Chang
5e46323ca3 Refactor tag()
This is much faster when there are large lists of children (and the code is
much simpler!)
2013-06-18 23:33:28 -05:00
Winston Chang
0a7d047246 Add tests for creating nested tags 2013-06-18 22:40:17 -05:00
Winston Chang
3fa534a3eb Add tests for adding children 2013-06-18 22:39:34 -05:00
Winston Chang
c6405f70d3 Add tagSetChildren() and tagAppendChildren() 2013-06-18 20:12:04 -05:00
Joe Cheng
acae6c2c49 Expose session$input and session$output
This makes it possible for packaged Shiny components to only ask
for the session variable to get access to all inputs and outputs
(along with the other good stuff on session).
2013-06-18 17:08:48 -07:00
Joe Cheng
141fdc2197 Do away with dependsOnFile error
This error is causing more problems than it solves.
2013-06-18 17:07:42 -07:00
Joe Cheng
a7ed8a006f includeText should be HTML escaped 2013-06-18 17:07:08 -07:00
Joe Cheng
b1a0ebd531 Add includeCSS and includeScript functions 2013-06-18 17:06:34 -07:00
Winston Chang
e8021acccd Speed up radioButtons when there are many choices 2013-06-17 23:49:50 -05:00
Winston Chang
39b0da2a3f Speed up selectInput when there are many choices 2013-06-17 23:44:13 -05:00
Joe Cheng
fd3d18f6c5 Add stopApp function, for returning a value from runApp 2013-06-14 22:27:58 -07:00
trestletech
ecc27d1674 Incorporated a worker ID specification.
Accept this as a parameter from the runApp() function and pass it through into the shinysession object so that it can be used in file uploads, downloads, and HTTP image fallbacks on non-websocket browsers.
2013-06-13 21:34:10 -07:00
Joe Cheng
7d0514ab36 Merge pull request #172 from wch/cairo-option
Add option for not using Cairo
2013-06-12 10:10:14 -07:00
Winston Chang
44c3024c00 Add option for not using Cairo 2013-06-12 10:56:21 -05:00
Winston Chang
253c92bab7 Bump version to 0.6.0.99 for development 2013-06-12 10:53:51 -05:00
Joe Cheng
c10850118d Merge pull request #170 from hadley/master
Fix typo
2013-06-11 13:26:14 -07:00
Joe Cheng
4f017e9173 Remove annoying title="foo" tooltip on all tabset tabs 2013-06-11 09:19:49 -07:00
Joe Cheng
5ed46c82cb Document observer methods 2013-06-11 09:18:57 -07:00
hadley wickham
64391e906d Update reactives.R
Add newline (guessing that's how it's supposed to be)
2013-06-11 10:37:02 -05:00
Joe Cheng
47b4ee07ab Merge pull request #165 from trestletech/master
Export validateCSSUnit function
2013-06-10 11:32:01 -07:00
trestletech
3000cbf763 Reorder namespace using latest roxygen2 code. 2013-06-07 16:33:19 -05:00
trestletech
76b3d314a8 Exported validateCSSUnit function. 2013-06-05 15:15:54 -05:00
Winston Chang
ba646de0ad Bump version to 0.6.0 2013-06-05 12:12:46 -05:00
Winston Chang
395f746a05 Update NEWS 2013-06-04 22:20:07 -05:00
Winston Chang
f7e57cd398 Update NEWS 2013-06-04 21:21:26 -05:00
Winston Chang
3ea6d97ed2 Documentation updates 2013-06-04 21:21:26 -05:00
Winston Chang
affc0d8b67 Remove sendJavascript 2013-05-31 10:48:39 -05:00
Joe Cheng
c637e310e9 Merge pull request #164 from jcheng5/suspend-bugfix
Fix several bugs relating to suspendWhenHidden
2013-05-28 08:58:52 -07:00
Joe Cheng
6ee7dcdd51 Fix several bugs relating to suspendWhenHidden
- If an output is bound in the UI before it exists on the server, the
  server will suspend the new output until something else causes
  manageHiddenOutputs to be triggered. The refactor in shiny.R sets
  the suspended flag to .shouldSuspend.
- As part of the previous refactor, we don't set suspendOnHidden in
  defineOutput; instead we leave it empty and .shouldSuspend knows
  what the default should be.
- In shiny.js, unbound controls were not being suspended. This was
  fixed by having sendOutputHiddenState be stateful; anything in
  a visible state that disappears on the next iteration is marked
  as hidden. Also unbindAll now calls sendOutputHiddenState.
2013-05-27 12:52:33 -07:00
Joe Cheng
23470267fe Merge pull request #163 from jcheng5/app-object
Run apps without creating files on disk
2013-05-24 22:07:36 -07:00
Winston Chang
4a92bb91df Initialize slider at correct time 2013-05-24 18:58:47 -05:00
Joe Cheng
69522c422c Fix rendering issues when slider gets too wide
Synced to jslider commit (from rstudio/jslider fork):
6de6ef7b2c788cbcec74dd51e0008e12247e6638
2013-05-23 12:02:43 -07:00
Joe Cheng
bc5e3524eb Export basicPage 2013-05-23 11:56:55 -07:00
Joe Cheng
479297fc35 Add basicPage function; like bootstrapPage with padding 2013-05-23 11:23:28 -07:00
Joe Cheng
516feafcfb Run apps without creating files on disk
With this commit, runApp can now accept a list instead of a path.
This list should have elements named "ui" and "server" that contain
what would normally go in shinyUI and shinyServer, respectively.
(Note that there is no equivalent to global.R, nor should there
need to be since you can just directly execute in the global env
before calling runApp.)

Example:

runApp(list(
  ui = bootstrapPage(
    numericInput('n', 'Number of obs', 100),
    plotOutput('plot')
  ),
  server = function(input, output) {
    output$plot <- renderPlot({ hist(runif(input$n)) })
  }
))
2013-05-23 10:00:38 -07:00
Joe Cheng
a135c82ab5 Merge pull request #160 from wch/reactive-timer
reactiveTimer: don't invalidate when session closed
2013-05-15 14:08:56 -07:00
Winston Chang
10996f1cbd reactiveTimer: don't invalidate when session closed 2013-05-15 15:50:37 -05:00
Joe Cheng
23b060e1f5 Merge pull request #159 from wch/session-invalidate
invalidateLater: don't invalidate when session closed
2013-05-15 11:32:09 -07:00
Winston Chang
622ff3a256 invalidateLater: don't invalidate when session closed 2013-05-15 12:41:07 -05:00
Winston Chang
5d457b6834 Bump httpuv version dependency 2013-05-15 12:09:21 -05:00
Winston Chang
f10f76d127 Fixes for R CMD check 2013-05-13 10:54:54 -05:00
Winston Chang
58f3382daf Update NEWS 2013-05-10 14:09:51 -05:00
Winston Chang
0e1139446e Merge pull request #149 from jcheng5/observer-priorities
Add priority levels to observers
2013-05-10 12:03:28 -07:00
Winston Chang
f433216fae Merge pull request #156 from jcheng5/fix-submit-button
Fix submit button interactions with tabs, plot sizes
2013-05-10 12:02:14 -07:00
Winston Chang
ed680baaac selectInput: correctly handle choices with duplicate names. Fixes #157 2013-05-08 18:32:05 -05:00
Winston Chang
e0a9d908ed Update NEWS 2013-05-06 11:14:42 -05:00
Winston Chang
bfa4a46bd5 Merge pull request #154 from wch/tag
Add withTags function
2013-05-06 08:46:09 -07:00
Winston Chang
03f3ff991e Update NEWS 2013-05-06 10:45:41 -05:00
Winston Chang
619b4824f0 Add tests for withTags 2013-05-06 10:45:41 -05:00
Winston Chang
021af0186b Add withTags function 2013-05-06 10:45:41 -05:00
Winston Chang
d3caad8b8d Add comment in test 2013-05-01 01:17:07 -04:00
Winston Chang
ec6bec3326 Fix selected items in checkboxGroupInput 2013-05-01 01:12:03 -04:00
Joe Cheng
dd54740d36 Fix submit button interactions with tabs, plot sizes 2013-04-29 13:08:04 -07:00
Winston Chang
8f65156bda Add Makefile for building web assets 2013-04-24 12:29:46 -05:00
Winston Chang
96c7df5afa Documentation fixes 2013-04-24 12:27:35 -05:00
Winston Chang
0c19105fbf Add dateInput and dateRangeInput
Also:
* add initialize() method for input bindings
* cleanups for JShint
2013-04-24 12:18:20 -05:00
Joe Cheng
4145d83248 Merge remote-tracking branch 'jcheng5/session-close-callbacks'
Conflicts:
	R/shiny.R
2013-04-23 15:40:38 -07:00
Winston Chang
6490705e2a Clarification of tagList help 2013-04-23 12:06:22 -05:00
Joe Cheng
10d2432df5 Merge pull request #148 from wch/sendmessage
Add support for sending arbitrary messages to client
2013-04-22 16:40:01 -07:00
Joe Cheng
815db72671 Add callback for session end 2013-04-22 16:29:40 -07:00
Joe Cheng
6d0ba61c54 Add priority to outputOption 2013-04-19 15:48:56 -07:00
Joe Cheng
5f61267f75 Allow integers or numerics for priority 2013-04-19 15:42:18 -07:00
Joe Cheng
94ee42cebb Add priority levels to observers
Observers can now take priority levels, which allow the user to control
the order of execution. Note that reactive expressions do not have
priority levels; since they are lazily evaluated, it wouldn't make any
sense to speak of priorities.

Another commit will be needed to add an API for changing the priorities
of outputs (probably in outputOptions?).
2013-04-19 10:34:34 -07:00
Winston Chang
b6795e5c63 Move actionbutton into Shiny proper 2013-04-18 15:11:13 -05:00
Winston Chang
ef85d063c2 Make external message handlers use 'custom' 2013-04-18 13:40:32 -05:00
Winston Chang
59755971e5 Add message handlers 2013-04-18 12:40:19 -05:00
Winston Chang
c5ab831a87 Fixes for jshint
Conflicts:
	inst/www/shared/shiny.js
2013-04-18 11:41:52 -05:00
Winston Chang
6715dc2a5d Merge pull request #139 from wch/set-input
Add ability to set inputs from server
2013-04-17 14:58:14 -07:00
Winston Chang
af6de64ec0 Add clientData to session object 2013-04-10 13:02:48 -05:00
Winston Chang
1ac2448f90 Split sendMessage into type-specific functions 2013-04-10 12:30:58 -05:00
Winston Chang
b5f34b30d3 Add documentation for input updater functions 2013-04-10 12:13:53 -05:00
Winston Chang
01f4e080df Workaround for Cairo resolution bug 2013-04-09 17:13:26 -05:00
Winston Chang
d55335e70b Make updateFooInput functions behave like fooInput functions 2013-04-08 18:38:16 -05:00
Winston Chang
a8c1dc4bc6 Add dropNulls function 2013-04-08 18:13:26 -05:00
Winston Chang
2897059503 Allow setting labels for all input objects 2013-04-08 18:09:40 -05:00
Winston Chang
d491f9df5a updateCheckboxGroupInput: clean up and allow setting labels 2013-04-08 17:01:00 -05:00
Winston Chang
bc40318e40 Wrap slider in div so that it can be manipulated more easily 2013-04-08 16:01:31 -05:00
Joe Cheng
3935434f04 Merge branch 'domain-sockets' 2013-04-06 20:44:40 -07:00
Joe Cheng
4cf1f2de94 Fix bug where multiple file uploads get same path
https://groups.google.com/d/msg/shiny-discuss/Km_pQL87paM/4V0AiIoTgwIJ

The problem is that length(.files) gives the number of columns in the
data frame, not the number of rows. So it's always either 0 or 4.
2013-04-06 18:14:21 -07:00
Winston Chang
73156c6780 Add update-input functions 2013-04-06 09:32:01 -05:00
Winston Chang
bc52bafa8d Add methods for setting bootstrapTabInputBinding 2013-04-06 01:00:18 -05:00
Winston Chang
5c9007b242 Streamline tests 2013-04-06 00:28:26 -05:00
Winston Chang
5857e3f75e Allow setting value of sliders when they have range 2013-04-05 22:56:12 -05:00
Winston Chang
e202831013 Add empty message tests 2013-04-05 21:57:45 -05:00
Winston Chang
4cbbfccb6d Make sure not to bind new-style multi-inputs 2013-04-05 21:57:45 -05:00
Winston Chang
21f3b1cf34 Add checkboxGroupInputBinding 2013-04-05 21:57:45 -05:00
Winston Chang
f7b384e9b6 Add radioInputBinding 2013-04-05 21:57:45 -05:00
Winston Chang
1e6ab47ee4 Fixes to tests for jshint 2013-04-05 21:57:45 -05:00
Winston Chang
78341ea2f1 Trigger change when message sent to input bindings 2013-04-05 21:57:45 -05:00
Winston Chang
3f8a4d4273 Add getState and receiveMessage support to selectInputBinding 2013-04-05 21:57:45 -05:00
Winston Chang
bae517c9f8 Align checkboxes with labels 2013-04-05 21:57:45 -05:00
Winston Chang
c88ccbf9bc Put inputMessage in a queue 2013-04-05 21:57:45 -05:00
Joe Cheng
5e40f5d509 Allow listening on domain sockets 2013-04-02 15:24:24 -07:00
Winston Chang
46389131bc Add functions for sending messages to client 2013-03-30 21:07:22 -05:00
Joe Cheng
c6a344d0d9 Add selected argument to tabsetPanel 2013-03-29 23:14:01 -07:00
Winston Chang
bcc2c377a0 Add messenge-sending support 2013-03-29 14:32:34 -05:00
Winston Chang
bb6afc847e Add input binding tests 2013-03-29 14:30:22 -05:00
Winston Chang
e0193151db shiny.js: allow setting inputs and getting input state 2013-03-28 16:15:24 -05:00
Winston Chang
42a80bad8e Undo license change 2013-03-28 10:45:26 -05:00
Joe Cheng
6e3e77f65d Code review feedback for version checking stuff 2013-03-25 11:26:16 -07:00
Winston Chang
e155f022a0 Bump version to 0.5.0 2013-03-22 22:49:55 -05:00
Joe Cheng
db65aab347 Give warning message on obsolete Shiny Server version 2013-03-22 14:33:44 -07:00
Winston Chang
a180c5f357 renderPlot: just return if width or height is NULL 2013-03-22 12:52:43 -05:00
Winston Chang
1c0279f17c Undo commit 'Remove redundant code in shiny.js'
The code wasn't actually redundant.
2013-03-22 12:51:29 -05:00
Winston Chang
8866eb292b Add section breaks in shiny.js 2013-03-21 21:09:16 -05:00
Winston Chang
6fdda3391e Send initial value of URL hash 2013-03-20 16:53:40 -05:00
Winston Chang
fdb8dd4e5b Remove redundant code in shiny.js 2013-03-20 13:22:21 -05:00
Joe Cheng
9a1d3783ee Unbind controls in htmlOutput before displaying error 2013-03-19 13:32:14 -07:00
Winston Chang
3841d9e322 Update license information 2013-03-18 15:33:12 -07:00
Winston Chang
e392eadf8a Update NEWS 2013-03-18 11:22:27 -07:00
Winston Chang
f743d5d0b5 New method for detecting hidden outputs 2013-03-17 11:08:28 -07:00
Winston Chang
4a76bf59ef Fix access to .clientData 2013-03-17 09:54:18 -07:00
Winston Chang
205b29e2f5 Update NEWS 2013-03-15 16:44:42 -05:00
Winston Chang
d511b82264 Add imageOutput function 2013-03-15 16:44:18 -05:00
Winston Chang
aaae112e60 Add to on.exit() instead of replace 2013-03-15 16:26:05 -05:00
Winston Chang
955fd6207f Change license to GPL>=2 2013-03-15 12:32:05 -05:00
Joe Cheng
4e56c96612 Fix allowDataUriScheme 2013-03-13 11:13:26 -07:00
Joe Cheng
dd046f3442 Merge remote-tracking branch 'jcheng5/master'
Conflicts:
	R/shiny.R
2013-03-13 10:47:06 -07:00
Winston Chang
5a947f83a1 Separate private and public fields for input and clientData 2013-03-12 21:41:38 -05:00
Winston Chang
b87b8b54fd Update NEWS 2013-03-12 16:14:28 -05:00
Winston Chang
233c0537a1 Merge pull request #122 from wch/url
Send URL components in clientData
2013-03-12 13:42:05 -07:00
Winston Chang
63d4798a50 Add tests for parseQueryString 2013-03-12 14:32:52 -05:00
Winston Chang
6c47517684 Move allowDataUriScheme into .clientdata 2013-03-12 14:24:48 -05:00
Winston Chang
c58b1a0143 Add parseQueryString function 2013-03-12 14:24:48 -05:00
Joe Cheng
f489d9131b File uploads failed when no content type was provided
The simple fix for this would've been to just guess the content
type on the server (or use empty string or something), but by
doing the fix this way we're also set up to handle uploads by
servers that don't allow custom headers on AJAX calls.
2013-03-12 09:50:01 -07:00
Winston Chang
f0109c5588 Send URL in clientdata 2013-03-11 18:44:58 -05:00
Winston Chang
c16becba56 renderTable: check for empty data frame. Fixes #55 2013-03-11 18:43:57 -05:00
Winston Chang
4605788696 Add informative comments 2013-03-11 18:43:03 -05:00
Joe Cheng
87908313cc Merge remote-tracking branch 'jcheng5/httpuv'
Conflicts:
	R/shiny.R
2013-03-11 09:36:47 -07:00
Winston Chang
9cc2eba7b8 Merge pull request #109 from wch/retina
Add clientdata channel for sending data

This branch includes support for Retina-resolution displays.
2013-03-11 07:45:24 -07:00
Winston Chang
2459cee57b Add renderImage function 2013-03-11 09:39:39 -05:00
Winston Chang
0bf6ce57ed renderPlot: send height and width along with image 2013-03-11 09:39:38 -05:00
Winston Chang
7041424f96 Add plotPNG function 2013-03-07 17:12:24 -06:00
Winston Chang
9509285c16 Rename ShinySession to saveFile 2013-03-07 17:12:24 -06:00
Winston Chang
e55ee0e65d Create ShinySession$sendFile() and use from renderPlot() 2013-03-07 17:12:18 -06:00
Winston Chang
9ea70497c2 Bump version to 0.4.1.99 for development 2013-03-06 17:26:35 -06:00
Joe Cheng
3389b9e9fd Memory-efficient file downloads 2013-03-05 23:06:13 -08:00
Winston Chang
76d4d54639 Allow shinyServer() to take clientData argument 2013-03-05 19:32:10 -06:00
Winston Chang
1b692b6c37 Rename shinyapp to shinysession, and .shinyout_xx to .clientdata_output_xx 2013-03-05 19:07:36 -06:00
Winston Chang
40d8cef1a2 Rename .metadata to clientData 2013-03-05 16:21:02 -06:00
Winston Chang
23550c0062 Add manageInputs() to handle metadata and normal inputs 2013-03-05 16:07:28 -06:00
Winston Chang
949bd940ee Partial change to reactiveValues 2013-03-04 20:33:29 -06:00
Winston Chang
79bdb9eed5 Add shiny metadata channel and send pixel ratio
This adds support for retina-resolution displays
2013-03-04 20:33:29 -06:00
Winston Chang
a141f08298 Bump version to 0.4.1 2013-03-04 20:27:48 -06:00
Joe Cheng
dee43a3911 Don't animate when showing file upload error 2013-03-04 14:47:26 -08:00
Joe Cheng
ef227d0139 More memory-efficient file uploading 2013-03-04 11:14:39 -08:00
Winston Chang
cbcf9ce645 reactivePlot: fix infinite recursion when height/width is function 2013-03-04 11:20:14 -06:00
Joe Cheng
0e5af2b16c Check for excessively large uploads before they begin
The onHeaders callback is supposed to be able to stop large uploads before
they begin, but do not appear to be having the desired effect. The browsers
continue uploading until completion, before noticing the response. To work
around this for now, upload the sizes explicitly when the job begins and
let Shiny pre-emptively reject the whole thing. This is also beneficial
in cases where multiple files are being uploaded and not all of them
exceed the maximum upload size.
2013-03-01 19:31:18 -08:00
Joe Cheng
85ca3a3b27 Update upload docs 2013-03-01 15:54:19 -08:00
Joe Cheng
fc5f5f3b6c Don't initiate file upload if no files were chosen 2013-02-28 21:14:06 -08:00
Joe Cheng
716fd8c0b9 File upload improvements
- Add "shiny.maxRequestSize" option
- Show upload progress
2013-02-28 21:06:06 -08:00
Joe Cheng
a517393c43 Remove dead upload code 2013-02-28 07:46:31 -08:00
Joe Cheng
c2311faffe httpuv-style file uploading
Use HTTP POST to upload files rather than sending 4K chunks
one at a time over the websocket. This is massively faster and
also means no binary websocket support is needed. In theory
this approach should be compatible with Shiny Server.

Currently the client side code still uses File API which means
IE8 and 9 users are out of luck.
2013-02-27 16:47:18 -08:00
Joe Cheng
fe453b0d66 Restore filter functionality 2013-02-26 16:59:56 -08:00
Joe Cheng
7e75b0fc02 eventloop package renamed to httpuv 2013-02-26 16:27:26 -08:00
Joe Cheng
11b0a0a73d Conform to API changes in eventloop package 2013-02-25 20:06:21 -08:00
Joe Cheng
82fdb5c3eb Greatly improve responsiveness of interruption on Windows 2013-02-25 15:14:24 -08:00
Joe Cheng
3f1d532c8b Restore startApp/serviceApp division of labor 2013-02-25 15:14:23 -08:00
Joe Cheng
f258b00aa7 Initial implementation on eventloop
Timers don't work yet
2013-02-25 15:13:30 -08:00
Winston Chang
4e71b9576d Update NEWS 2013-02-25 15:11:24 -06:00
Winston Chang
f36567a5cd reactivePlot: correctly pass width and height to renderPlot 2013-02-25 12:35:39 -06:00
Winston Chang
924ebb6c7f Bump version to 0.4.0.99 for development 2013-02-22 15:30:04 -06:00
Winston Chang
6e7e8eb44a Bump version to 0.4.0 2013-02-21 16:50:01 -06:00
Winston Chang
308c583254 setRatePolicy based on effectiveId. Fixes #110
Previously when getType() was defined for a type of object, shiny.js would
send updates immediately instead of applying the rate policy.
2013-02-20 11:39:22 -06:00
Winston Chang
97b2f7e5ca Fix call to manageHiddenOutputs in timer callback. Fixes #112 2013-02-19 12:20:49 -06:00
Winston Chang
3ea88a07d9 sliderInputBinding inherits from text instead of number. Fixes #110 2013-02-18 22:25:38 -06:00
Winston Chang
588f8bb96a Merge pull request #107 from wch/numeric-na
Empty numericInput gets converted to NA
2013-02-18 14:01:04 -08:00
Winston Chang
c93c0dd721 Update NEWS 2013-02-18 16:00:25 -06:00
Winston Chang
fc59c254fd Merge pull request #108 from wch/unused-hidden
Treat unused outputs as hidden
2013-02-18 13:56:49 -08:00
Winston Chang
2f8b6a150f Treat unused outputs as hidden 2013-02-18 15:53:31 -06:00
Winston Chang
db60ac5c17 Empty numericInput gets converted to NA 2013-02-18 15:11:41 -06:00
Winston Chang
e1f09853c5 Make shiny.deprecation.messages option actually work 2013-02-17 16:17:41 -06:00
Winston Chang
24656713a5 Remove unnecessary function() in renderXX 2013-02-17 12:02:00 -06:00
Winston Chang
7dd0269292 Update NEWS 2013-02-14 14:09:42 -06:00
Winston Chang
8b87cea7aa Merge pull request #104 from wch/reactive-exp
Change reactive() and observe() to take expressions
2013-02-14 12:08:18 -08:00
Winston Chang
c7559a6946 Suspend overwritten output objects 2013-02-14 12:14:08 -06:00
Winston Chang
945c6080ad Export exprToFunction 2013-02-14 11:48:01 -06:00
Winston Chang
44590965d1 Add renderXX Rd files 2013-02-14 11:48:01 -06:00
Winston Chang
7ab64d678f reactivePlot: call height and width properly 2013-02-14 11:48:01 -06:00
Winston Chang
e406a76b62 Update documentation for renderXX 2013-02-14 11:48:01 -06:00
Winston Chang
e26f175a8f Change reactiveXX to renderXX 2013-02-13 12:11:39 -06:00
Winston Chang
d4ab84745d Make function for expr-to-function conversion 2013-02-12 15:55:51 -06:00
Winston Chang
32dbc3101e Add shinyDeprecated function 2013-02-12 15:24:50 -06:00
Winston Chang
0a924eb718 Fix deprecation message for observe() 2013-02-12 15:24:50 -06:00
Winston Chang
a284327bfc Re-roxygenize 2013-02-12 15:24:50 -06:00
Winston Chang
2ea38d6ecc Clean up instances of reactive() and observe() 2013-02-12 15:24:50 -06:00
Winston Chang
6a34bbfddd Add label argument to reactive and observe 2013-02-12 15:24:50 -06:00
Winston Chang
58323ada4b Change references of reactive 'functions' to 'expressions' 2013-02-12 15:24:49 -06:00
Winston Chang
5fd723cb80 reactive() and observe() now take expressions 2013-02-12 15:24:49 -06:00
Winston Chang
5c626e6957 Documentation fixes 2013-02-12 15:24:39 -06:00
Winston Chang
5d949842eb Add garbage collection tests 2013-02-11 20:26:23 -06:00
Winston Chang
b595c17d78 observe: add option to start suspended 2013-02-11 19:48:22 -06:00
Winston Chang
b84973ba2b Remove leftover testing string 2013-02-11 19:36:06 -06:00
Winston Chang
61be49e7b2 Merge pull request #97 from wch/suspend-hidden
Suspend hidden outputs. Fixes #24
2013-02-11 16:48:39 -08:00
Winston Chang
8faf5659ee Re-roxygenize 2013-02-11 18:47:53 -06:00
Winston Chang
cc9267a646 manageHiddenOutputs: check that output object exists 2013-02-11 18:45:45 -06:00
Winston Chang
55838bb032 Call manageHiddenOutputs after timer callbacks 2013-02-11 18:37:18 -06:00
Winston Chang
67619ac5e8 Don't allow another flush if currently in one 2013-02-11 18:35:32 -06:00
Winston Chang
952b342859 Better checks for hidden output objects 2013-02-11 18:31:44 -06:00
Winston Chang
c7149c460d Add documentation for suspendWhenHidden option 2013-02-11 16:08:30 -06:00
Winston Chang
fd0613ea0e Call manageHiddenOutputs when suspendWhenHidden is set 2013-02-11 15:16:04 -06:00
Winston Chang
36d2dddc59 Run manageHiddenOutputs on app init 2013-02-09 00:02:52 -06:00
Joe Cheng
63c5b05584 Stop extra update message from occurring on startup 2013-02-08 16:37:55 -08:00
Winston Chang
4b235e5b87 Send output hidden state on init 2013-02-07 14:29:03 -06:00
Winston Chang
6c51fffdaa Fix tests 2013-02-07 14:29:03 -06:00
Winston Chang
5d6d638c85 Clarify suspend description 2013-02-07 14:29:03 -06:00
Winston Chang
90eb515167 Observer: .flushCallbacks to .invalidateCallbacks 2013-02-07 14:29:03 -06:00
Joe Cheng
17526711a2 Change resume behavior for Observer
Eliminate multiple runs when resumed multiple times
2013-02-07 14:29:03 -06:00
Winston Chang
cf0118e090 Add tests for suspended observers 2013-02-07 14:29:03 -06:00
Winston Chang
868d6fec42 Add suspended option to Observer 2013-02-07 14:29:03 -06:00
Winston Chang
851f5854bf Add outputOptions function 2013-02-07 14:29:03 -06:00
Winston Chang
eb5428c971 Suspend hidden outputs 2013-02-07 14:29:03 -06:00
Winston Chang
81188df7ef Update runUrl help and re-document 2013-02-07 10:46:20 -06:00
Winston Chang
9fd365cc41 isolate help: mention debugging use and fix typos 2013-02-06 14:38:12 -06:00
Winston Chang
999df6e40f httpResponse: make sure headers is a list. Fixes #102 2013-02-06 12:29:24 -06:00
Winston Chang
076d069568 runGist: accept new URL format with username 2013-02-06 12:06:14 -06:00
Joe Cheng
2738648197 Merge pull request #101 from jcheng5/chrome-frame
Chrome Frame compatibility
2013-02-05 15:18:03 -08:00
Joe Cheng
36013009a1 Chrome Frame compatibility 2013-02-05 15:15:03 -08:00
Winston Chang
1b60233862 Fix closing brace in isolate help 2013-02-05 10:56:54 -06:00
Winston Chang
2cba10dd05 Follow redirects with curl for http
The previous logic added the -L option to curl when downloading https, but
    not for http.
2013-02-04 13:06:15 -06:00
Winston Chang
b3944127ea Add note about using local() with isolate() 2013-02-01 15:16:33 -05:00
Winston Chang
f1674378ca Remove unneeded reactive() wrappers 2013-01-31 15:47:02 -05:00
Winston Chang
6f0191e1cf Block some operators for shinyoutput objects 2013-01-31 15:45:31 -05:00
Winston Chang
1848844be6 Cleaner method for creating objects with class 2013-01-30 15:06:17 -05:00
Winston Chang
8b6362c749 Add section markers 2013-01-30 15:04:55 -05:00
Winston Chang
d860d13361 Add comments to test 2013-01-30 15:04:50 -05:00
Winston Chang
4b077dbf4c Observers can be suspended/resumed 2013-01-30 14:47:19 -05:00
Winston Chang
40f73bbfe2 Bump version to 3.1.99 for development 2013-01-30 13:51:54 -05:00
Winston Chang
f455706d7c Bump version to 0.3.1 2013-01-29 21:16:44 -05:00
Winston Chang
23e9672476 Update NEWS 2013-01-26 13:16:42 -06:00
Winston Chang
36f992f95f Add [[<-.shinyoutput operator 2013-01-26 13:08:40 -06:00
Joe Cheng
b2c6d526ab Merge pull request #92 from wch/fix-download
Use correct default label for contexts. Fixes #91
2013-01-25 13:17:04 -08:00
Winston Chang
fe1e833677 Use correct default label for contexts. Fixes #91
NULL apparently is not a valid value for a field in a reference class.
2013-01-25 14:57:05 -06:00
Joe Cheng
8df1b9e8e5 Merge pull request #85 from jcheng5/flush-all
Flush all shinyapp instances
2013-01-25 08:52:51 -08:00
Joe Cheng
38b0f71b01 Merge pull request #89 from wch/reactive-invisible
Store visibility state of functions called from Observable
2013-01-25 00:47:42 -08:00
Winston Chang
29d2f115f8 Better reactiveText test 2013-01-24 23:10:02 -06:00
Winston Chang
0f677b4891 Add tests for reactive function return visibility 2013-01-24 22:45:07 -06:00
Winston Chang
2f7dd04168 Observable: save visibility state of function 2013-01-24 21:57:49 -06:00
Winston Chang
ed3b667985 Remove unneeded eval.parent 2013-01-24 21:38:25 -06:00
Joe Cheng
6ae1d8c158 Flush all shinyapp instances
Allows reactivity to affect all app instances at once.
(It already does but the outputs don't currently update)
2013-01-24 13:48:05 -08:00
Winston Chang
404bced97b Bump version to .99 for development 2013-01-24 13:58:58 -06:00
Winston Chang
5af49c8a82 Bump version and update NEWS 2013-01-23 14:54:39 -06:00
Winston Chang
85aa98e8e2 Fixes for R CMD check 2013-01-23 14:30:11 -06:00
Joe Cheng
330d102f62 Fix test on Linux (sort locale) 2013-01-23 12:17:45 -08:00
Joe Cheng
32b33a7910 Add res dir to .Rbuildignore 2013-01-23 12:13:40 -08:00
Joe Cheng
17c6a0f28a Merge branch 'reactivePrint-invisible'
Conflicts:
	man/plotOutput.Rd
2013-01-23 12:09:53 -08:00
Joe Cheng
7341eed1cf Merge pull request #80 from wch/run-github
Add functions runGithub and runUrl
2013-01-23 12:06:46 -08:00
Joe Cheng
ff99fbfbc9 Fix #64: Hitting Enter in textbox causes form submit 2013-01-23 11:54:06 -08:00
Winston Chang
9f67fdc771 Re-document 2013-01-23 13:44:18 -06:00
Winston Chang
521143a16b Add subdir argument for runGitHub and runUrl 2013-01-23 13:44:17 -06:00
Winston Chang
2622a25b12 Add runGitHub and runUrl functions 2013-01-23 13:44:17 -06:00
Joe Cheng
a91e925221 Remove failure comment 2013-01-23 11:33:06 -08:00
Joe Cheng
6c3289d5a5 Documentation and examples for reactivePrint/reactiveText 2013-01-23 11:32:13 -08:00
Joe Cheng
988a91ac06 reactiveText shouldn't capture print output 2013-01-23 11:31:51 -08:00
Winston Chang
aa7c913e9a Escape percent sign in documentation 2013-01-23 09:42:08 -06:00
Joe Cheng
56db9feaa4 reactivePrint should not display invisibles 2013-01-22 23:36:51 -08:00
Winston Chang
5ace0f13c9 Move validateCssUnit to separate function 2013-01-23 00:02:16 -06:00
Winston Chang
076e6c9479 Re-roxgenize 2013-01-22 23:25:36 -06:00
Winston Chang
8277b1192e Update NEWS 2013-01-22 23:23:02 -06:00
Winston Chang
150b978b0e Fix tests with reactiveValuesToList 2013-01-22 23:22:41 -06:00
Winston Chang
6c72096bfe Better CSS unit validation 2013-01-22 19:18:18 -06:00
Winston Chang
87c18cea80 Merge pull request #79 from wch/better-deps
Finer grained dependencies when converting reactiveValues to list
2013-01-22 17:15:38 -08:00
Winston Chang
e658734084 Rename reactivevalues_to_list to reactiveValuesToList 2013-01-22 19:14:30 -06:00
Winston Chang
ec4f350baa reactivevalues_to_list: add all.names option 2013-01-22 14:53:14 -06:00
Winston Chang
095f583211 Deprecate as.list.reactivevalues and add reactivevalues_to_list 2013-01-22 14:51:43 -06:00
Winston Chang
3c864cf6d2 reactiveValues(): improved check for unnamed arguments 2013-01-22 13:59:31 -06:00
Joe Cheng
eb4b21ce9f Fix #77: tagWriteChildren error 2013-01-21 22:40:08 -08:00
Joe Cheng
ff5349fd90 Fix #65: tagWrite doesn't expect strings except as direct children of tags 2013-01-21 16:31:09 -08:00
Winston Chang
1f34ffa85d plotOutput: check that height has proper format 2013-01-18 19:16:50 -06:00
Winston Chang
e98cab1f7c Fix test 2013-01-17 00:11:38 -06:00
Winston Chang
aabc9659a2 Update NEWS
Some news items were under the wrong version heading. Those have also been
fixed.
2013-01-16 23:00:07 -06:00
Winston Chang
8d8d308f7a Rename 'dependencies' to 'dependents' 2013-01-16 22:42:03 -06:00
Winston Chang
3ebd4595c6 Add read-write wrapper class for ReactiveValues 2013-01-16 19:02:26 -06:00
Winston Chang
7e1168946f Re-roxygenize 2013-01-16 16:08:12 -06:00
Joe Cheng
134689d8aa Remove subsetting operators from Map and Values
The correct operators would be [[/[[<- but since we don't use them I
just removed them instead.
2013-01-16 13:48:50 -08:00
Winston Chang
56282f9cbb Merge branch 'lazy' 2013-01-16 12:32:32 -06:00
Joe Cheng
b4713741b1 Two new recursion/circularity tests 2013-01-16 10:27:20 -08:00
Joe Cheng
e42fe3bd61 Fix problem with circular dependencies
The first of the included tests did not pass without the changes to
Observable. The problem occurred when a function read a reactive value
and then wrote it. Any dependents on the function would not receive
any invalidations, then or ever after.

The first problem was that the dirty state was unilaterally set to FALSE
after the function finished executing, which might not be accurate if
the function's newly created was invalidated during its own execution.
Instead we set dirty state to FALSE before executing. But to prevent
reentrant calls from thinking the cached value can be used, we add
a .running field that is also consulted during getValue.

The second problem was that Observable$getValue didn't register the
dependent until after updateValue. That is a problem if updateValue
creates *and* invalidates a context before returning. So now we
register the dependent before calling updateValue.
2013-01-15 17:37:26 -08:00
Winston Chang
4fd2dade60 reactiveTable: don't return blank if first element is NA. Fixes #71 2013-01-15 16:04:18 -06:00
Joe Cheng
e12b03504c Fix bad calls to on.exit
I didn't realize on.exit replaces previous calls to on.exit by default.
2013-01-15 12:07:27 -08:00
Winston Chang
153156c1fa Add back onInvalidate to Observer class 2013-01-15 11:13:46 -06:00
Winston Chang
3ecc69da2b Un-export execCount 2013-01-15 11:13:46 -06:00
Winston Chang
07ad29da41 Clarify isolation test 2013-01-15 11:13:46 -06:00
Winston Chang
7d0de0b26f Remove onInvalidateHint
The recent changes to onInvalidate make it do almost exactly the same thing.
2013-01-15 11:13:46 -06:00
Winston Chang
77fab9c78f Remove all pendingInvalidate 2013-01-15 11:13:46 -06:00
Winston Chang
3a8f3272c7 Don't call observers until flushReact() 2013-01-15 11:13:46 -06:00
Joe Cheng
2d44cbac1b Failing overreactivity test 2013-01-08 14:06:10 -06:00
Joe Cheng
893d72677b Try LIFO pendingInvalidates? 2013-01-08 14:06:10 -06:00
Joe Cheng
979eca4066 Add execCount 2013-01-08 14:06:10 -06:00
Joe Cheng
258d13e746 Add ctx$.label to help with debugging
Shows the code that the context "belongs" to.
2013-01-08 14:06:10 -06:00
Winston Chang
779531da5d Use lazy evaluation of reactive functions 2013-01-08 14:06:10 -06:00
Winston Chang
31d71006d7 Add tests for isolate() 2013-01-08 14:06:10 -06:00
Winston Chang
64ca66c062 Add test for reactive evaluation order 2013-01-08 14:06:10 -06:00
Winston Chang
6e1a2b3427 reactive tests: count number of times observers are run 2013-01-08 14:06:10 -06:00
Winston Chang
f585235192 Add reactivity tests 2013-01-08 14:06:10 -06:00
Winston Chang
9355643554 Update NEWS 2013-01-08 14:03:23 -06:00
Winston Chang
ccc6055926 Fix reactivity for empty checkbox groups. Fixes #58 2013-01-08 13:57:10 -06:00
Joe Cheng
6639446bb8 Update README.md 2013-01-07 22:39:07 -08:00
Joe Cheng
e2925c585f Add isolate function for accessing reactives non-reactively 2013-01-03 12:16:50 -08:00
Joe Cheng
6c76b0473c Add implementation of reactive values 2013-01-02 16:00:21 -08:00
Joe Cheng
e1e19632a5 Update URL in DESCRIPTION 2012-12-21 14:46:52 -08:00
Winston Chang
3e5364d5c0 Bump version number to .99 for development 2012-12-18 11:17:12 -06:00
Winston Chang
6c98de4c8b Update NEWS 2012-12-17 16:24:40 -06:00
Winston Chang
9613dde4d2 Increment version to 0.2.4 2012-12-17 15:30:08 -06:00
Winston Chang
d47df2e538 Re-roxygenize 2012-12-17 15:23:59 -06:00
Winston Chang
6fcacd5159 Use different method of accessing CairoPNG
R CMD check didn't like Cairo::CairoPNG. With this method, check wants
Cairo to be imported in NAMESPACE, but it shouldn't be - Cairo should
be optional.
2012-12-17 15:23:08 -06:00
Winston Chang
11b39cb020 Change maintainer 2012-12-17 14:30:47 -06:00
Winston Chang
d81f132db6 Update NEWS 2012-12-17 13:40:50 -06:00
Winston Chang
095697e789 Use new URL for runGist. Fixes #57 2012-12-17 12:18:19 -06:00
Joe Cheng
62d98c3137 Revert "Run invalidated hints only once per context"
This reverts commit e80d5dc172.

The original commit could cause under-reporting of progress.
2012-12-14 16:41:12 -08:00
jeffreyhorner
e80d5dc172 Run invalidated hints only once per context 2012-12-13 16:02:47 -06:00
jeffreyhorner
421e29db2d Suppress base64 output when tracing websocket messages 2012-12-13 16:00:58 -06:00
Joe Cheng
9e6e53583c Merge pull request #49 from wch/png-cairo
For png output, try quartz and CairoPNG before plain png
2012-12-05 09:56:11 -08:00
Joe Cheng
3f59a7d84e Fix bug where reactiveUI doesn't accept plain lists 2012-12-05 09:54:31 -08:00
Winston Chang
21ffd788ab For png output, try quartz and CairoPNG before plain png 2012-12-03 12:06:31 -06:00
Joe Cheng
8dadfea724 Separate request parameters from path; version 0.2.3 2012-11-30 09:31:09 -08:00
Joe Cheng
00ce52ecf7 Fix CRAN warning; version 0.2.2 2012-11-30 09:05:20 -08:00
Joe Cheng
50ac13d3fd [BREAKING] Modify API of downloadHandler
The `content` function now takes a file path, not writable connection, as an argument.
This makes it much easier to work with APIs that only write to file paths, not
connections.
2012-11-29 17:14:44 -08:00
Joe Cheng
58318fec46 Update package metadata for v0.2.0 2012-11-27 16:32:27 -08:00
Joe Cheng
a49941113e Require Shiny at app startup
Some of our examples omit library(shiny) from the top of ui.R and server.R,
which worked fine before but not with the namespace fix from yesterday.
Requiring shiny at startup fixes the problem.
2012-11-27 16:29:01 -08:00
Joe Cheng
595801cb99 Trivial style copy edits to example 10_download 2012-11-26 21:48:12 -08:00
Joe Cheng
0b469f09df Fix subtle name resolution bugs
See in particular:
http://stackoverflow.com/questions/13575353/how-does-the-shiny-r-package-deal-with-data-frames

Also reported at different times by Dirk Eddelbuettel and Jay Emerson.

The observed behavior is that S3/S4 method dispatch does not always seem to
work; the desired methods are not invoked despite appearing to be in the
search path.

The problem was that sourcing files with local=TRUE creates a new environment
based on the parent frame, which in our case is Shiny's package environment.
What we really want is to read from the global environment but write to a
throwaway environment. The correct way to do that is to make a new environment
with .GlobalEnv as the parent.
2012-11-26 21:45:28 -08:00
Joe Cheng
1e1f4e4a47 Update metadata for 0.1.14 2012-11-24 01:47:47 -08:00
Joe Cheng
c63e2ae7c8 Fix slider animation controls 2012-11-24 00:30:44 -08:00
Joe Cheng
d3d3fa990e Update version metadata 2012-11-23 23:47:27 -08:00
Joe Cheng
21980b7e71 Clean up PNG file when no longer needed 2012-11-23 22:44:37 -08:00
Joe Cheng
844ca0d387 I am stupid. 2012-11-21 23:02:40 -08:00
Joe Cheng
972ae35300 Update metadata for 0.1.12 2012-11-21 22:44:19 -08:00
Joe Cheng
57bfb8eb96 Bring untar operations in-house
Very simple tweak to R's untar2 code was all that was
required to fix the built-in untar's problems with
gists. Seemed best to just fork it and start using
the forked version directly, regardless of what is
installed on your machine.
2012-11-21 22:37:47 -08:00
Joe Cheng
ed6e6a9fb2 Squash another cygwin warning 2012-11-21 21:43:32 -08:00
Joe Cheng
ed402267b6 Fix runGist cygwin warning bug 2012-11-21 21:39:16 -08:00
Joe Cheng
6eec570828 Add CSS hooks for app-wide busy indicators 2012-11-21 00:04:16 -08:00
Joe Cheng
22fc1e3f0b Add param docs 2012-11-20 18:08:59 -08:00
Joe Cheng
ae9bd868f1 Implement arbitrary file downloads 2012-11-20 17:42:34 -08:00
Joe Cheng
a887012aca Update metadata for v0.1.11 2012-11-19 17:22:57 -08:00
Joe Cheng
bc73048ab9 Fix IE8 slice bug
IE8 doesn't like slice(0, undefined)--rather than interpreting it as slice(0),
it returns an array of length 0.
2012-11-19 17:19:51 -08:00
Joe Cheng
c89dd6c379 Fix issue #41: reactiveTable should allow print options too 2012-11-19 15:26:34 -08:00
Joe Cheng
9662debe5e Dynamic plot sizing 2012-11-19 15:26:02 -08:00
Joe Cheng
057262d917 Update metadata for v0.1.10 2012-11-19 13:11:07 -08:00
Joe Cheng
b6723a6219 Add per-session GET infrastructure. Allow IE8/9 to avoid data URIs. 2012-11-19 13:08:09 -08:00
Joe Cheng
068f3e0a43 Merge pull request #32 from edwindj/master
small bug: checkboxInputGroup sets html attribute "selected" in stead of "checked"
2012-11-15 23:30:28 -08:00
Joe Cheng
95635a8c47 Issue #37: headerPanel HTML argument shows up in title 2012-11-13 01:52:33 -08:00
Joe Cheng
3ec2071820 Address issue #35: Allow modification of untar args 2012-11-13 00:09:27 -08:00
Joe Cheng
1696db3044 Fix issue #36: reactiveUI does not always correctly render sliders
There is a deeper problem here, that reactiveUI output that renders stuff to the <head> will generally not work. We're not in a position to fix that yet and this problem has been reported twice, so we'll just fix this instance by making the slider dependencies built into the framework.
2012-11-11 18:32:34 -08:00
Joe Cheng
e1a1eab2b3 More MIME types 2012-11-10 15:18:29 -08:00
Edwin de Jonge
f7865f3358 changed html attribute of checkboxInputGroup from "selected" into "checked" 2012-11-08 23:09:08 +01:00
Joe Cheng
6d5f8ed5f3 Pointer to Shiny homepage 2012-11-08 03:29:23 -08:00
Joe Cheng
96a737379f Add linked example 2012-11-07 10:36:42 -08:00
Joe Cheng
d73feec013 Turns out GitHub doesn't like iframes 2012-11-07 10:28:47 -08:00
Joe Cheng
2ccead1da5 Add example to README 2012-11-07 10:28:06 -08:00
Joe Cheng
8885f2717e Update version 2012-11-06 13:53:53 -08:00
Joe Cheng
4448ffc777 Add methods for including text, HTML, and Markdown files in UI 2012-11-06 13:38:52 -08:00
Joe Cheng
022d10c598 Export and document observe function 2012-11-06 10:03:11 -08:00
Joe Cheng
8e6b7043bd Shut down timer callbacks before runApp returns 2012-11-06 09:36:49 -08:00
Joe Cheng
66eaaff598 More customizable error display 2012-11-02 09:49:17 -07:00
Joe Cheng
478c6c134f Much less flicker when updating plots 2012-11-02 09:48:36 -07:00
Joe Cheng
b5d333ba6c Rev downloader code 2012-10-31 15:36:52 -07:00
Joe Cheng
81723d55ac Change T and F to TRUE and FALSE
TRUE and FALSE are keywords whereas T and F are just predefined variables that can be reassigned
2012-10-31 11:35:41 -07:00
Joe Cheng
fb784ce962 Merge pull request #28 from rstudio/list-to-vec
Change lists to vectors in UI elements
2012-10-31 10:00:21 -07:00
Winston Chang
5a37380900 Capture stderr in download() 2012-10-30 16:19:14 -05:00
Joe Cheng
b6300f3a5c More robust setInternet2 workaround 2012-10-30 12:31:36 -07:00
Winston Chang
a3e8a2d623 Re-roxygenize 2012-10-30 10:49:55 -05:00
Winston Chang
7b3a4bdc39 Use vectors instead of lists in UI elements 2012-10-30 10:47:05 -05:00
Joe Cheng
cc0b5e5e0f Remove problematic link (fails R CMD check)
I first attempted to remove \code, but I couldn't figure out how to get the # in the URL to work right under both web-based help and PDF.
2012-10-29 11:56:59 -07:00
Joe Cheng
5c3f7d8f94 Update NEWS 2012-10-29 11:47:27 -07:00
Joe Cheng
8c3f8cd450 Add wellPanel and bootstrapPage functions 2012-10-29 11:45:58 -07:00
Joe Cheng
046582711a Update NEWS 2012-10-29 11:22:30 -07:00
Joe Cheng
15756ec92d Case insensitive probing for server.R, ui.R, et al 2012-10-29 11:19:23 -07:00
Joe Cheng
fc49abc9fb Fix issue #27: Warnings cause reactive functions to stop executing 2012-10-29 11:09:13 -07:00
Winston Chang
4a9ff27f3e Download gists in binary mode 2012-10-26 16:38:18 -05:00
Joe Cheng
790e6f370f Remove RCurl dependency 2012-10-26 14:07:07 -07:00
Joe Cheng
16ccc1321d Update docs 2012-10-26 10:46:42 -07:00
Joe Cheng
8648c94dd4 Update version to 0.1.8 2012-10-26 10:43:53 -07:00
Joe Cheng
dc4eb720ae Introduce input type hints
These allow the server to use custom deserialization code on a per-type basis.
2012-10-26 10:28:40 -07:00
Joe Cheng
0b891ad557 Run a GitHub gist 2012-10-25 20:41:52 -07:00
Joe Cheng
e96193ae28 Do .Random.seed restoring correctly 2012-10-24 23:19:13 -07:00
Joe Cheng
3ff9075959 Update NEWS 2012-10-24 21:11:56 -07:00
Joe Cheng
c03842056c Convert JSON to UTF-8
If reactivePrint or reactiveText return non-ASCII characters on
Windows, it causes invalid UTF-8 strings to be received by the
browser which closes the websocket connection.

I'm not sure this is the right place to do encoding, but it seems
to me like this approach is likely to work best for the most
users (especially those who just aren't thinking about encoding).
If you want to handle encoding in the reactives themselves (for
example), use `options(shiny.transcode.json=F)`.
2012-10-24 21:10:09 -07:00
Joe Cheng
6df226b21c Add repeatable utility function to stabilize RNGs 2012-10-24 16:12:08 -07:00
Joe Cheng
7dfa7d7426 Fix issue #26: Shiny.OutputBindings not correctly exported 2012-10-24 14:41:32 -07:00
Joe Cheng
b8b1a891cf Add custom message handler support, console logging
If the server sends a message with a "custom" field, that field's value will
be passed to a custom window.Shiny.oncustommessage function, if it is defined.

Also add support for messages like so:
{
  console: [
    'line one',
    'line two'
  ]
}

This will cause "line one" and "line two" to be printed at the browser console.
2012-10-04 17:45:20 -07:00
Joe Cheng
7df0e8b0f9 Update docs for 0.1.6 2012-09-25 03:08:31 -07:00
Joe Cheng
ff072ae9d9 bindAll should send initial values to server 2012-09-25 01:29:52 -07:00
Joe Cheng
f81ca39741 Add uiOutput. Tweak comments. 2012-09-25 00:33:00 -07:00
Joe Cheng
3db1f2a98c Don't animate showing/hiding of conditionalPanel 2012-09-21 19:51:24 -07:00
Joe Cheng
4865df9be1 Mark fileInput and reactiveUI as experimental. 2012-09-21 19:50:50 -07:00
Joe Cheng
0c16f2c334 Fix broken imports 2012-09-21 14:00:03 -07:00
Joe Cheng
d01149620f Fix issue #19: Checkboxes and radios can't be added dynamically 2012-09-19 11:48:28 -05:00
Joe Cheng
ab9401f390 Fix issue #20: DESCRIPTION file should use Imports instead of Depends 2012-09-19 11:47:12 -05:00
Joe Cheng
3223c17b74 Update websockets dependency version 2012-09-15 00:52:04 -07:00
Joe Cheng
404035bcf0 Bump version number 2012-09-14 19:16:03 -07:00
Joe Cheng
a0185bb0b4 Introduce shiny.http.response.filter option
Allows post-processing of HTTP responses
2012-09-14 13:15:58 -07:00
Joe Cheng
1a591cd9f1 conditionalPanel now triggers show/shown/hide/hidden event 2012-09-07 00:44:20 -07:00
Joe Cheng
e9b81b2033 [BREAKING] Simplify input binding callbacks
InputBinding.subscribe used to have to call callbacks with at least two arguments,
now there is only one optional argument (allowDeferred). The binding argument in
particular was problematic because it required "var self=this;".
2012-09-06 12:06:15 -07:00
Joe Cheng
cbfc1e8ed1 Add reactiveUI output type 2012-09-05 15:22:34 -07:00
Joe Cheng
cb63338805 Allow htmlOutput to contain inputs/outputs 2012-09-05 11:17:39 -07:00
Joe Cheng
bcdc82ccee Add conditionalPanel; JS API changes
- bindAll/unbindAll added
- bindInput/bindOutput/unbindInput/unbindOutput removed
2012-09-05 09:40:40 -07:00
Joe Cheng
76a4cf6c34 Update NEWS 2012-08-31 23:21:04 -07:00
Joe Cheng
872f23b0f0 Improvements for output binding/unbinding
- When bound, outputs receive cached error/value
- On binding, (potentially all) output plot sizes are resent
2012-08-31 23:12:20 -07:00
Joe Cheng
e61f7405fd Upload example app should accept text/plain files 2012-08-31 22:39:45 -07:00
Joe Cheng
0714871b56 Improve blob handling browser compatibility 2012-08-31 22:39:26 -07:00
Joe Cheng
8a89fb2a1a Expose and fix Shiny.unbindOutputs 2012-08-31 18:29:42 -07:00
Joe Cheng
036544e3ed Eagerly evaluate output name 2012-08-31 12:33:13 -07:00
Joe Cheng
7a6784d809 Add missing param to prototype method 2012-08-31 11:48:21 -07:00
Joe Cheng
ed9301705b Refactor JS to use more consistent OOP style
(function() { }).call(Foo.prototype) for extending prototypes manually, and
$.extend for extending objects manually or prototypes inheriting from each
other.
2012-08-31 10:00:20 -07:00
Joe Cheng
21f9694574 Add NEWS for file upload 2012-08-30 22:10:16 -07:00
Joe Cheng
3a0b11b89d Add file upload feature
This feature is currently pretty rough. It only works in the most modern
browsers (depends on HTML5 File API, including Blob.slice) and doesn't
show upload progress.
2012-08-30 22:07:00 -07:00
Joe Cheng
d5272e3e74 Update version 2012-08-30 12:27:05 -07:00
Joe Cheng
b5197869db Update NEWS 2012-08-30 12:18:46 -07:00
Joe Cheng
5f775db40a Enhancements to Shiny transport
- JS can now do remote procedure calls (with return value or exception), not just message passing
- RPC calls can include non-JSON-compatible binary data (not compatible with IE)
2012-08-30 12:16:12 -07:00
Joe Cheng
9b84b83627 Allow binding and unbinding of Shiny input/output 2012-08-30 12:04:17 -07:00
Joe Cheng
b0d9b5762a Don't use WebSocket constant, it's not on IE8 2012-08-24 11:28:46 -07:00
Joe Cheng
8d9fd402be Check inheritance properly 2012-08-23 18:07:09 -07:00
Joe Cheng
73a44a4f8e Packages can register their own URL namespace
Helpful for serving up custom stylesheets, CSS, images, etc.
2012-08-23 13:08:08 -07:00
Joe Cheng
a7dd62249e Add checkboxGroupInput control 2012-08-22 13:39:19 -07:00
Joe Cheng
42fac871fb Extensible websocket creation 2012-08-22 12:32:33 -07:00
Joe Cheng
2782bf6735 Execute sendPlotSize when anything is shown/hidden 2012-08-21 14:18:00 -07:00
Joe Cheng
f2a1ce4977 Update NEWS 2012-08-21 14:16:25 -07:00
Joe Cheng
c8969c4cc0 Upgrade to Bootstrap 2.1 2012-08-21 11:35:37 -07:00
Joe Cheng
cfefb4a07c Update NEWS 2012-08-20 17:16:23 -07:00
Joe Cheng
653509368b Let Bootstrap tabset send its selected tab as input 2012-08-20 17:01:41 -07:00
Joe Cheng
51b269f329 roxygen2 on my dev box
For some reason my machines can't agree on the order of the NAMESPACE file
2012-08-20 13:49:28 -07:00
Joe Cheng
c92d2cc32e Documentation for numericInput(step) 2012-08-20 13:46:36 -07:00
Joe Cheng
cb4091895a Fix S3 generic method consistency 2012-08-20 13:44:04 -07:00
Joe Cheng
b96bc5a710 Fix broken roxygen declaration 2012-08-20 13:43:49 -07:00
Joe Cheng
4ace825c58 Add step param to numericInput 2012-08-20 13:32:10 -07:00
Joe Cheng
589e0f7bb5 Bump version/date 2012-08-20 10:05:58 -07:00
Joe Cheng
347b9e1d7a Add NEWS 2012-08-20 10:05:16 -07:00
Joe Cheng
363633b01f Fix issue #10: Plots in tabsets not rendered 2012-08-20 09:54:50 -07:00
Joe Cheng
575350842a Fix broken progress indication 2012-08-18 00:01:38 -07:00
Joe Cheng
d49e8d172f Improvements to reactives and UI
- `input` object now implements names() and as.list()
- Simpler dependency tracking impl using Dependencies class
- New `singleton` function for making HTML content appear only once
- Fix issue #4: head deduplication should not be line-oriented
2012-08-18 00:01:16 -07:00
Joe Cheng
642d153202 Dynamic output bindings 2012-08-14 01:21:25 -07:00
Joe Cheng
8cf7d8b4cb Input binding enhancements
- Add textarea binding
- Deterministic priority ordering
- Allow getting/setting priorities for existing bindings
2012-08-14 00:58:56 -07:00
Joe Cheng
b0b7cfa3a5 Remove comment cruft 2012-08-13 14:45:49 -07:00
Joe Cheng
3692d5f008 Delay Shiny init to after document-ready
Also remove some dead code
2012-08-13 11:51:53 -07:00
Joe Cheng
2344dc04a5 Fix bug in deferred submission 2012-08-13 10:09:44 -07:00
Joe Cheng
cf37072bed Don't debounce when animating 2012-08-13 10:04:06 -07:00
Joe Cheng
cc5c933e7d Use InputBinding for sliders 2012-08-09 17:13:14 -07:00
Joe Cheng
ad1737f16b Infrastructure for extensible inputs 2012-08-09 16:38:21 -07:00
Joe Cheng
2ac1895a6e Inputs without names shouldn't be sent 2012-08-08 17:13:19 -07:00
Joe Cheng
4dc7630adc Cleanup code, exports, radio values
- Radio values based on id could not be kept in sync because implicitly deselected radios don't trigger a change event. So don't pass id-based values for radios at all (still works for checkboxes though)
- Make onInputChange available in a Shiny namespace on the window
- Remove no longer used debounce/throttle code
2012-08-07 15:25:00 -07:00
Joe Cheng
66a3d68755 Hook up modular input pipeline 2012-08-07 15:25:00 -07:00
Joe Cheng
ce9213cdc1 Infrastructure for more flexible input handling 2012-08-07 15:25:00 -07:00
Joe Cheng
99b1ed51a6 Update install instructions
Adding ourselves to the repo list means we don't have to serve up
all the CRAN dependencies on our repo.
2012-08-06 15:40:05 -07:00
Joe Cheng
c7dcff56c7 New, simpler install instructions 2012-08-02 18:11:49 -07:00
Joe Cheng
fcdb8f08b8 Bump version 2012-08-02 14:02:32 -07:00
Joe Cheng
daa03999b6 Fix error when no ui.R file exists
Error message was:
'Error: argument "handler is missing, with no default'

Previously I was intentionally allowing the main dynamicHandler code to run, intending to allow ui.R to be created even after the application started. Hopefully I can bring that capability back when I figure out more deeply why the error is happening.
2012-08-02 13:55:32 -07:00
JJ Allaire
cd7c5dc048 add .Rprofile to gitignore 2012-07-30 06:55:25 -07:00
JJ Allaire
09f0f85b9c update README with installation instructions 2012-07-30 08:02:57 -04:00
JJ Allaire
8aee7563f0 bump version to 0.1.1 2012-07-30 07:27:07 -04:00
Joe Cheng
6d6c8cecd6 Fix path bug on Windows 2012-07-29 18:39:10 -07:00
JJ Allaire
334f6c8757 sync readme to welcome 2012-07-29 11:00:03 -07:00
Joe Cheng
8455343fee Only instantiate sliders if sliders are loaded 2012-07-29 11:04:27 -07:00
JJ Allaire
d234ab016f tweaks to readme 2012-07-29 08:54:43 -07:00
JJ Allaire
a312b46e97 man page for shiny-package 2012-07-29 08:32:55 -07:00
JJ Allaire
ff06c7997b update package DESCRIPTION 2012-07-29 08:12:53 -07:00
JJ Allaire
3dc6d84d1f docs for output elements 2012-07-29 07:39:44 -07:00
JJ Allaire
ef74483ebb fix types in bootstrap docs 2012-07-29 07:39:24 -07:00
JJ Allaire
d8cf7bcbf8 docs for tabsets 2012-07-29 07:02:04 -07:00
JJ Allaire
33336a7ad2 docs for text and numeric inputs 2012-07-29 06:21:26 -07:00
JJ Allaire
79865b39d1 docs for radio buttons and submit button 2012-07-29 06:12:52 -07:00
JJ Allaire
375125e992 additional control docs 2012-07-29 06:03:39 -07:00
JJ Allaire
ebc5a992dc remove docs for startApp 2012-07-29 05:40:48 -07:00
JJ Allaire
da01184fc9 remove more unexported functions from docs 2012-07-29 05:36:13 -07:00
JJ Allaire
e0a6a6c558 remove internal functions from docs 2012-07-29 05:34:48 -07:00
JJ Allaire
93ec81bc57 break tag/tagAppendChild out into a separate help topic 2012-07-29 05:27:57 -07:00
JJ Allaire
29295fa8a7 add client param (rd file checkin) 2012-07-29 05:15:42 -07:00
JJ Allaire
74e7130bee fix typo in main panel docs 2012-07-29 05:15:08 -07:00
JJ Allaire
30cd83662a add docs for client param to registerClient 2012-07-29 05:14:49 -07:00
JJ Allaire
5f8f3ca328 fix type in mainPanel example 2012-07-29 05:14:32 -07:00
JJ Allaire
5744f1c7ee don't export tagWrite or tagWriteChildren 2012-07-29 04:57:24 -07:00
JJ Allaire
ba05f03359 simple docs shims for clearClients and registerClient 2012-07-29 04:54:44 -07:00
JJ Allaire
43c9ed0655 document top level shiny ui defintion functions 2012-07-29 04:40:57 -07:00
JJ Allaire
43fa8f53d3 eliminate problematic usage section for HTML Builder Functions 2012-07-29 04:16:36 -07:00
JJ Allaire
258dad0389 change usage of tags in docs (was yielding a warning) 2012-07-29 04:13:50 -07:00
JJ Allaire
5d5eaa2065 update namespace 2012-07-29 03:45:51 -07:00
Joe Cheng
1329136792 Get rid of R CMD CHECK warnings 2012-07-28 14:26:13 -07:00
Joe Cheng
c6cbcff9ce Document HTML function 2012-07-28 14:25:53 -07:00
Joe Cheng
ed2e637596 Fix bug where HTML() nodes were still being escaped 2012-07-28 14:24:54 -07:00
Joe Cheng
c97aecf9ff Document and enhance builder functions
Add easy string conversion and printing
2012-07-28 14:00:50 -07:00
JJ Allaire
9672088158 remove helpText from animation example 2012-07-28 11:12:23 -04:00
JJ Allaire
995908d3c6 remove docs since they have been folded into the tutorial 2012-07-28 11:04:49 -04:00
JJ Allaire
74314457ba update readme 2012-07-28 05:06:22 -07:00
Joe Cheng
d64c99ed28 Fix broken Rd link 2012-07-28 01:54:33 -07:00
Joe Cheng
38bf13e9bf Add doc for sliderInput's animate param 2012-07-28 01:52:41 -07:00
Joe Cheng
4101c1efd0 Rd docs for observe, reactive, reactiveTimer
Also improve some error messages
2012-07-28 01:47:19 -07:00
Joe Cheng
f095700485 Rd docs for runApp, runExample, shinyServer 2012-07-28 01:17:21 -07:00
Joe Cheng
4ff1c95083 Slider and animation docs 2012-07-27 17:46:15 -07:00
Joe Cheng
c3e14933e2 Use simpler output format for 05_sliders 2012-07-27 14:46:11 -07:00
Joe Cheng
1b3cf52a17 More control over slider animation
- Slider now takes animate argument that expects NULL, TRUE, FALSE, or a list that can be constructed using animationOptions()
- Update examples/05_sliders to use new animation format
- Tweak spacing around slider
2012-07-27 14:45:22 -07:00
Joe Cheng
e2f8163b21 Change git URL to SSH-style 2012-07-27 14:34:35 -07:00
Joe Cheng
54d3e1a5e1 Serialize logical attrib values using lowercase 2012-07-27 14:05:40 -07:00
Joe Cheng
57e088f6e1 Implicit initialization of jslider 2012-07-27 14:05:12 -07:00
Joe Cheng
c759dcd7df Add htmlOutput function 2012-07-27 13:21:08 -07:00
Joe Cheng
033eb41a1d Make slider send only 1 event per animation frame 2012-07-27 13:21:08 -07:00
JJ Allaire
77f6e138ac shorten first readme bullet 2012-07-27 13:17:32 -07:00
JJ Allaire
c5c70b0f49 bold recommended 2012-07-27 13:16:41 -07:00
JJ Allaire
6b37e026fd update readme 2012-07-27 13:15:33 -07:00
JJ Allaire
731018082b Merge branch 'master' of github.com:rstudio/shiny 2012-07-27 12:57:26 -07:00
JJ Allaire
a7eab9f00e use c for install packages 2012-07-27 12:57:19 -07:00
Joe Cheng
0d3aebc077 Slider improvements
- Get rid of smooth--it doesn't make sense for our purposes since we always provide step
- Don't do any rounding by default (this required changes in jslider)
- Switch order of format and locale arguments
- Animation should pause automatically when it reaches the end
- Default to 1s animation interval
- If animation is started when sliders are at the end, restart
- Animation button click target ran the width of the slider
2012-07-27 11:52:57 -07:00
JJ Allaire
fb37e3254d updated readme 2012-07-27 11:40:21 -07:00
JJ Allaire
6d9da1260a add comments to sliders example 2012-07-27 09:53:32 -07:00
JJ Allaire
0d749f333a don't use as.integer since it's no longer required 2012-07-27 09:34:03 -07:00
JJ Allaire
338463057c initial code for slider example 2012-07-27 09:05:23 -07:00
JJ Allaire
35c131f661 use span for textOutput 2012-07-27 08:05:52 -07:00
Joe Cheng
da6771eaae Back out accidentally-committed test code 2012-07-27 01:37:24 -07:00
Joe Cheng
fbf3623343 Add rudimentary animation to sliders 2012-07-27 01:35:09 -07:00
Joe Cheng
2d43817b2f Slider improvements, typed input values
- Slider now has 'smooth' parameter that, if false, snaps slider to step
- Two-handle slider (provide a vector of length 2 to value=)
- Slider and number inputs yield numeric values
2012-07-26 17:43:45 -07:00
Joe Cheng
01905c51dd Expose more slider options, add tick logic 2012-07-26 17:43:45 -07:00
JJ Allaire
84494b8a0a dont import datasets into mpg ui 2012-07-26 10:12:50 -07:00
JJ Allaire
aded289558 use reactiveText where appropriate 2012-07-26 10:07:35 -07:00
JJ Allaire
f1462fa0d2 fix spelling error 2012-07-26 09:21:41 -07:00
JJ Allaire
5cfd546b2a change indentation for tabset app 2012-07-26 09:18:14 -07:00
JJ Allaire
3b38792481 user new header panel syntax for tabsets 2012-07-26 07:27:04 -07:00
JJ Allaire
31b347e8dd headerPanel now includes a title element and just inserts a plain h1 2012-07-26 07:22:41 -07:00
JJ Allaire
d87149ab5d roxygenzie 2012-07-25 19:01:49 -07:00
JJ Allaire
fd2f4789d3 inlcude radioButtons in example 6 2012-07-25 19:01:38 -07:00
Joe Cheng
0d8d35743d Observers defer first execution until flushReact
This allows us to greatly simplify the way outputs are defined
2012-07-25 16:07:40 -07:00
Joe Cheng
b5a65040b3 Comment tweaks 2012-07-25 15:50:11 -07:00
Joe Cheng
d44289f036 reactiveText -> reactivePrint 2012-07-25 15:30:53 -07:00
Joe Cheng
cb4b45aff1 Support radio/checkbox; unlist input lists when unnamed 2012-07-25 14:53:08 -07:00
JJ Allaire
0f4851e77d add comment noting immediate rendering of caption 2012-07-25 14:44:54 -07:00
JJ Allaire
42fe86e024 add comments for examples 7 and 8 2012-07-25 14:42:50 -07:00
JJ Allaire
3bb0ebb98f add comments for example 6 2012-07-25 14:33:49 -07:00
JJ Allaire
391310faa5 add main server comment for examples 3 and 4 2012-07-25 14:26:56 -07:00
JJ Allaire
ab0552f409 different prefix for output comments 2012-07-25 14:21:04 -07:00
JJ Allaire
8a6f59e350 add comments to example 4 2012-07-25 14:19:38 -07:00
JJ Allaire
8e859e53c2 add comments to examples 2 and 3 2012-07-25 14:12:52 -07:00
JJ Allaire
a44e475451 add comments to example 1 2012-07-25 14:02:31 -07:00
JJ Allaire
f958839af1 load mpgData at startup 2012-07-25 11:16:04 -07:00
JJ Allaire
f741851250 eliminate animation example 2012-07-25 11:01:18 -07:00
JJ Allaire
acd68b5de8 more widgets example 2012-07-25 10:10:03 -07:00
JJ Allaire
466ea7277f correct handling of variable inputs for helpText and HTML functions 2012-07-25 10:09:39 -07:00
JJ Allaire
c80072a62e example 2 should use a reactive function 2012-07-25 10:09:03 -07:00
JJ Allaire
bc0a37e8da export radioButtons function 2012-07-25 10:07:09 -07:00
JJ Allaire
a323f40da2 stubs for examples we haven't built yet 2012-07-25 09:36:42 -07:00
JJ Allaire
ee05e6ba03 use numeric sequences for example directories 2012-07-25 09:32:32 -07:00
JJ Allaire
ae9ef5c13f use mpg dataset for user example 2012-07-25 12:20:27 -04:00
JJ Allaire
fcc90df31c implement radioButtons (note that initial value isn't correctly sent right now) 2012-07-25 11:53:50 -04:00
JJ Allaire
d6b6719b54 rename model function to formulaText 2012-07-25 11:15:33 -04:00
JJ Allaire
21e8af827f add titanic example 2012-07-25 09:42:53 -04:00
JJ Allaire
5e5d233d83 add library(datasets) where required 2012-07-25 09:20:55 -04:00
JJ Allaire
214fd92b12 add html ui example 2012-07-25 09:14:20 -04:00
JJ Allaire
3687790730 remove br tags from reactivity example 2012-07-25 08:57:33 -04:00
JJ Allaire
d0f86078aa add tabsets example 2012-07-25 08:51:18 -04:00
JJ Allaire
649cb69466 allow helpText to take multiple strings 2012-07-25 08:47:38 -04:00
JJ Allaire
2f342e7664 remove allcaps and hash examples 2012-07-25 08:40:29 -04:00
JJ Allaire
e4fccc2f84 add reactivity example 2012-07-25 08:37:10 -04:00
JJ Allaire
61bd2d356b add text example 2012-07-25 08:07:36 -04:00
JJ Allaire
66ddb6ce0a make min and max optional for numeric input 2012-07-25 08:06:23 -04:00
JJ Allaire
573b3b1dfd tweak hello initial value 2012-07-25 08:04:58 -04:00
JJ Allaire
560bd3ca85 use condensed style for tables 2012-07-25 02:48:02 -07:00
Joe Cheng
1f5fe5b570 Use Sys.time instead of C code 2012-07-24 22:09:23 -07:00
Joe Cheng
d18d2df417 More robust runExample logic 2012-07-24 21:53:16 -07:00
Joe Cheng
91731a86bf Fix CSS for jslider 2012-07-24 18:47:14 -07:00
Joe Cheng
7108761e8f Bootstrap-styled tables
Other UI packages can override the table styles by using the option shiny.table.class.
2012-07-24 18:36:02 -07:00
Joe Cheng
0fe8bacf73 Integrate slider, more efficient input event handling 2012-07-24 18:20:11 -07:00
Joe Cheng
ef1afb482f common.R => global.R 2012-07-24 14:12:44 -07:00
JJ Allaire
134a3de256 hello sample app 2012-07-24 13:32:04 -07:00
JJ Allaire
71975546cb add support for select multiple attribute 2012-07-24 13:26:49 -07:00
Joe Cheng
b4c02f42f7 Add support for progress indication
The CSS class 'recalculating' will be added to any output elements whose content might be affected by a change to one or more of the inputs.
2012-07-24 10:45:00 -07:00
JJ Allaire
da7210f43f rename server function to shinyServer 2012-07-24 02:53:48 -07:00
Joe Cheng
8b4d62e374 Error handling support (very basic) 2012-07-23 17:10:19 -07:00
JJ Allaire
b68da2c3d3 add jslider component 2012-07-23 13:54:01 -07:00
JJ Allaire
b2db41c7f4 remove submit button from example 3 2012-07-23 12:08:54 -07:00
JJ Allaire
c4922d1655 insert name/value handling for selectList (now has same behavior as manipulate) 2012-07-23 12:08:26 -07:00
JJ Allaire
94ca77e697 remove html tags from example 3 2012-07-23 11:43:43 -07:00
JJ Allaire
c1d076ef79 change name of selectListInput to selectInput 2012-07-23 11:43:09 -07:00
JJ Allaire
39c69a4aff bind directly to shiny css class names 2012-07-23 11:39:16 -07:00
JJ Allaire
5a0921ed74 flesh out Readme.md 2012-07-23 11:23:44 -07:00
JJ Allaire
68c668615f add runExample function for easily running examples from within the tutorial 2012-07-23 09:01:36 -07:00
JJ Allaire
e1d5876ae6 move doc and examples to inst directory 2012-07-23 08:59:29 -07:00
JJ Allaire
741910407f change applicationPage to pageWithSidebar 2012-07-23 08:50:21 -07:00
JJ Allaire
39d4befc54 make tags module responsible for the export of the HTML function 2012-07-23 08:49:56 -07:00
JJ Allaire
d13505ce91 eliminate withTags construct 2012-07-23 08:42:45 -07:00
JJ Allaire
8c6d586fb0 fix HTML function 2012-07-23 06:04:31 -07:00
JJ Allaire
f66c2967dd use panel suffix for tab components 2012-07-23 05:53:20 -07:00
JJ Allaire
ef44a2295f export html tags from shinyui module rather than tags module 2012-07-23 05:09:50 -07:00
JJ Allaire
6186231041 unify naming convention for tags module 2012-07-23 04:59:17 -07:00
JJ Allaire
25ec5550b5 remove jslider component 2012-07-23 03:15:54 -07:00
JJ Allaire
1f93610a95 add COPYING and NOTICE files 2012-07-23 02:10:04 -07:00
JJ Allaire
01cde51a71 liveText should not include a label (should be done at a higher level in the system) 2012-07-23 01:53:32 -07:00
JJ Allaire
7d054c11de submit button: change default caption and ensure it is wrapped in a block element 2012-07-22 09:21:15 -07:00
JJ Allaire
98f717d5b4 add comment on slider control source/dependencies 2012-07-22 07:52:20 -07:00
JJ Allaire
6f315144cc factor slider into core slider function and sliderInput wrapper for integration into bootstrap forms 2012-07-22 07:47:36 -07:00
JJ Allaire
9ba8f569db merge 2012-07-22 10:15:20 -04:00
JJ Allaire
51f169571f add primary style to submit button 2012-07-22 10:14:14 -04:00
JJ Allaire
b6a9ffb4c7 initial implementaiton of slider control 2012-07-22 10:13:58 -04:00
JJ Allaire
346612aac1 initial implementaiton of slider control 2012-07-22 10:11:47 -04:00
JJ Allaire
205144d92d add support for form submit button 2012-07-21 18:40:33 -07:00
JJ Allaire
af2e321f45 add helpText widget 2012-07-21 18:31:32 -07:00
JJ Allaire
e22a20701b automatically generate ids for tabsets 2012-07-21 13:28:05 -07:00
JJ Allaire
f3edde8f81 add HTML function for including raw html 2012-07-21 13:12:50 -07:00
JJ Allaire
f405a0c905 perform html escaping of attribs and text 2012-07-21 12:50:51 -07:00
JJ Allaire
4907df497f use more natural attribute names now that we need to use withTags less often 2012-07-21 12:31:51 -07:00
JJ Allaire
e551c42f32 export some additional commonly used html tags 2012-07-21 12:18:12 -07:00
JJ Allaire
0c1a235cc1 ensure that attribute names don't conflict with tag names 2012-07-21 12:03:44 -07:00
JJ Allaire
5384b3a8c0 explicitliy specify h1 element in headers 2012-07-21 12:03:00 -07:00
JJ Allaire
0acb5f5857 export a small set of text and heading oriented html tags 2012-07-21 11:45:34 -07:00
JJ Allaire
cee124a4d6 use padding rather than br for header panel 2012-07-21 11:44:42 -07:00
JJ Allaire
084b983b44 change name of application to applicationPage so as to be less likely to conflict with future apis 2012-07-21 11:21:58 -07:00
JJ Allaire
bf15948275 add some padding to the top of the header panel 2012-07-21 11:21:23 -07:00
JJ Allaire
8796875128 change name of createTag function to tag 2012-07-21 10:55:48 -07:00
JJ Allaire
af9c2b1449 rename shiny core output functions with live prefix 2012-07-20 18:50:22 -07:00
Joe Cheng
f0d6b6f558 Hot-reload of server.R 2012-07-20 15:59:56 -07:00
Joe Cheng
3778e01d7c Hot-reload of ui.R 2012-07-20 15:16:05 -07:00
JJ Allaire
70ebad0410 rename client.R to ui.R 2012-07-20 14:01:57 -07:00
JJ Allaire
7cf58bd864 improve names of functions in tags.R 2012-07-20 13:29:53 -07:00
JJ Allaire
5858483fca use withTags where appropriate 2012-07-20 13:20:38 -07:00
JJ Allaire
fb94d2a99c Merge branch 'master' of github.com:rstudio/shiny 2012-07-20 12:42:15 -07:00
JJ Allaire
55b5441f00 implement withTags 2012-07-20 12:42:08 -07:00
Joe Cheng
bf397e496c Add option for printing websocket traffic 2012-07-20 12:06:42 -07:00
Joe Cheng
a78ae8ca4a Don't plot unless width and height are positive 2012-07-20 12:06:42 -07:00
JJ Allaire
c635b92991 re-organize bootstrap.R 2012-07-20 12:06:31 -07:00
JJ Allaire
53d406f640 eliminate labelOnTop option 2012-07-20 11:59:38 -07:00
JJ Allaire
701f4b743b rename functions to clarify shiny core vs. bootstrap 2012-07-20 11:52:10 -07:00
JJ Allaire
7466baf1b2 support for otuput tabsets 2012-07-20 11:31:58 -07:00
JJ Allaire
13ecf8ef21 use bootstrap for example 3 2012-07-20 08:53:04 -07:00
JJ Allaire
c946a3973a use standard html attribute names for components whenever possible 2012-07-20 08:04:31 -07:00
JJ Allaire
615f265c00 bootstrap for examples 1 and 2 2012-07-20 07:52:35 -07:00
JJ Allaire
4177ba7840 eliminate withTags (couldn't get it to work properly) 2012-07-20 05:11:33 -07:00
JJ Allaire
393593b2d2 roxygenize 2012-07-19 19:01:22 -07:00
Joe Cheng
e736c3949a Use new client.R/server.R scheme 2012-07-19 14:26:01 -07:00
JJ Allaire
e1509e7db3 recursively include lists of lists of tags 2012-07-19 13:12:37 -07:00
JJ Allaire
49150b07fd correctly handle lists of tags 2012-07-19 13:03:25 -07:00
JJ Allaire
1d8f1b4c6a unpack var args before calling createTag 2012-07-19 12:57:09 -07:00
JJ Allaire
833f0c67cf Merge branch 'master' of github.com:rstudio/shiny 2012-07-19 12:48:20 -07:00
JJ Allaire
4b559b5a94 break tags into their own namespace 2012-07-19 12:48:15 -07:00
Joe Cheng
55c8d60cfb Add Bootstrap 2.0.4 to shared resources 2012-07-19 11:14:40 -07:00
JJ Allaire
0e129379e9 use html builder for example 2 2012-07-19 08:44:35 -07:00
JJ Allaire
7e3f704285 add textInput function 2012-07-19 08:10:04 -07:00
JJ Allaire
d8a595ac70 change clientUI -> clientPage 2012-07-19 06:57:00 -07:00
JJ Allaire
c13cb9b723 remove example code from ui.R 2012-07-19 06:41:43 -07:00
JJ Allaire
8cc83855b9 replace defineUI and page functions with single clientUI function (page conflicted with base::page and having a single function seemed simpler) 2012-07-19 06:41:16 -07:00
JJ Allaire
faebbf5753 Merge branch 'master' of github.com:rstudio/shiny 2012-07-19 06:38:03 -07:00
JJ Allaire
3e297bad1f use withHeadTags function rather than head directly (since it conflicted with base::head) 2012-07-19 06:33:07 -07:00
JJ Allaire
f56949dd0b use withHeadTags function rather than head directly (since it conflicted with base::head) 2012-07-19 06:08:07 -07:00
Joe Cheng
04081ec2d3 Integrate UI builder into Shiny
Replace example #1 HTML with builder
2012-07-18 15:27:27 -07:00
JJ Allaire
442f3d93c6 Merge branch 'master' of github.com:rstudio/shiny 2012-07-18 17:53:08 -04:00
Joe Cheng
b41d9bff51 HTML escaping utility function 2012-07-18 14:44:44 -07:00
JJ Allaire
7e1cd68cb4 comment out example/demo code 2012-07-18 17:06:16 -04:00
JJ Allaire
47675633d2 only self-close void elements 2012-07-18 16:54:02 -04:00
JJ Allaire
8e59834989 Merge branch 'master' of github.com:rstudio/shiny 2012-07-18 16:36:25 -04:00
JJ Allaire
a87c3cdb88 add doctype and charset to html header 2012-07-18 16:36:17 -04:00
Joe Cheng
b2f9903e18 Allow dynamic rendering of front-ends 2012-07-18 13:04:35 -07:00
JJ Allaire
a48c8056f2 allow attributes without values via NA 2012-07-18 15:56:01 -04:00
JJ Allaire
dfd6b85296 defer varargs processing until tag function 2012-07-18 15:43:58 -04:00
JJ Allaire
f3aed1bd53 more work on html builder 2012-07-18 15:41:36 -04:00
Joe Cheng
41716d160b Change startApp/runApp signature
Also change example apps to launch directly using runApp
2012-07-18 09:00:32 -07:00
Joe Cheng
bd87be2f7e Tweak docs 2012-07-18 09:00:32 -07:00
JJ Allaire
9bd4ad6e47 first stab at html generation syntax 2012-07-18 08:56:08 -07:00
JJ Allaire
9bd0c01bdd more scaffolding for ui module 2012-07-18 03:32:04 -07:00
JJ Allaire
7dc6b4035a add initial scaffolding for ui module 2012-07-18 03:25:40 -07:00
JJ Allaire
3a65b9e0e5 update reactivePlot docs 2012-07-18 03:25:14 -07:00
Joe Cheng
569b98c724 Update Example 3 to use auto-sized plot 2012-07-17 23:00:48 -07:00
Joe Cheng
3de022ba05 Add autosizing to reactive plots
Autosizing meaning the plot's HTML tag's clientside width and height will automatically be used by the renderer
2012-07-17 23:00:32 -07:00
Joe Cheng
b697718826 Add client throttle/debounce support
Also add 500ms debounce to input keyup/change
2012-07-17 22:58:57 -07:00
Joe Cheng
a16f7b34ab Allow output functions to access shinyapp and their name 2012-07-17 22:57:47 -07:00
Joe Cheng
0660ddbfbf Values keys that start with . were not reactive 2012-07-17 22:28:22 -07:00
Joe Cheng
f1a4bf4dd7 Allow deferred submission of input 2012-07-16 16:28:53 -07:00
Joe Cheng
06c319d1aa remove launchApp 2012-07-16 11:24:39 -07:00
Joe Cheng
2d89749c9b Include docs for launch.browser param 2012-07-16 09:37:12 -07:00
Joe Cheng
696bee13af Better interactive app lifecycle management
- When runApp returns, close the server socket
- Optionally launch browser when runApp is called
2012-07-16 09:30:35 -07:00
Joe Cheng
c5b835186c Keep R responsive when running interactively 2012-07-16 09:12:49 -07:00
Joe Cheng
ea3c1dacea Take version number out of jquery filename 2012-07-16 09:12:49 -07:00
JJ Allaire
7de29090db add launchApp function to run an app asynchronously and open it in a web browser 2012-07-16 06:18:57 -07:00
JJ Allaire
d982d15fbc sleep for 100ms around calls to serviceApp (makes huge improvement in IDE responsiveness while apps are running) 2012-07-16 05:30:48 -07:00
Joe Cheng
4455810b5b Ignore Mac build directories 2012-07-13 12:23:00 -07:00
Joe Cheng
00a8372a74 Fix some Rd formatting issues 2012-07-13 02:29:19 -07:00
Joe Cheng
108dd4ff24 Add invalidateLater API call
Provides a simpler mechanism for doing time-based invalidation of reactive functions.
2012-07-13 02:29:03 -07:00
Joe Cheng
8a687851f2 Allow multiple clients to connect; doc improvements
- Multiple clients can now connect on a single port, and each one gets a unique shinyapp instance
- Improve docs for reactiveXXX functions
- Simplify interface for running an app
2012-07-13 00:29:17 -07:00
Joe Cheng
52394d61bf Add time infrastructure, reactiveTimer 2012-07-12 16:36:32 -07:00
Joe Cheng
270d97f3db Merge remote-tracking branch 'upstream/master'
Conflicts:
	shiny.Rproj
2012-07-12 10:56:20 -07:00
Joe Cheng
c5b7e549ec Pass input/output args to app func 2012-07-12 01:59:50 -07:00
Joe Cheng
891a93a7a3 Update gitignore 2012-07-12 01:49:00 -07:00
Joe Cheng
13c7800c8c Add function for getting sys time in millis 2012-07-12 01:46:02 -07:00
JJ Allaire
e89f5de680 add build type to project file 2012-07-10 12:45:30 -04:00
Joe Cheng
c4fdd04fb4 Allow running in package form 2012-07-04 14:24:58 -07:00
Joe Cheng
500501497f Roxygenize 2012-07-04 14:11:35 -07:00
Joe Cheng
4106161753 Initial pass at packaging 2012-07-02 12:15:44 -07:00
Joe Cheng
8ce5a23c4b Rename flush.react to flushReact 2012-07-02 12:03:15 -07:00
Joe Cheng
5c524af472 Use camel case for all functions and fields 2012-06-29 17:09:07 -07:00
Joe Cheng
4b1123c4e4 Simplify output API 2012-06-29 15:53:10 -07:00
Joe Cheng
c3268d0362 Simplify API 2012-06-29 09:34:15 -07:00
Joe Cheng
f3fa9883aa Don't crash on errors in callbacks 2012-06-28 22:33:21 -07:00
Joe Cheng
8cf7ec9738 Drop 'shiny' from func names; layout changes 2012-06-28 22:27:22 -07:00
Joe Cheng
7c3a92662f Make websocket URL port independent 2012-06-27 14:50:18 -07:00
Joe Cheng
e05358db1d Add summary to example 3 2012-06-27 14:43:56 -07:00
Joe Cheng
74d450703c Add script for windows 2012-06-27 11:38:33 -07:00
Joe Cheng
aee4f3780c Stop using private functions from websockets 2012-06-27 11:19:32 -07:00
Joe Cheng
3aa0702ff8 Plots can now use <img> 2012-06-27 11:10:22 -07:00
Joe Cheng
cc51dbd4e6 Improve default table styles 2012-06-27 10:44:49 -07:00
Joe Cheng
228a83e0a7 Ignore .Rhistory 2012-06-27 00:01:25 -07:00
Joe Cheng
ee1ed1e9e5 Update README, add proj file 2012-06-27 00:00:55 -07:00
Joe Cheng
6a394cc30e Remove Ruby implementation... *sniff* 2012-06-26 21:56:13 -07:00
343 changed files with 69707 additions and 10500 deletions

13
.Rbuildignore Normal file
View File

@@ -0,0 +1,13 @@
^\.Rproj\.user$
^\.git$
^examples$
^shiny\.Rproj$
^shiny\.sh$
^shiny\.cmd$
^run\.R$
^\.gitignore$
^res$
^man-roxygen$
^\.travis\.yml$
^staticdocs$
^tools$

2
.Rinstignore Normal file
View File

@@ -0,0 +1,2 @@
^tools$
^Rmd$

12
.gitignore vendored
View File

@@ -1,4 +1,10 @@
vendor/ruby
\.bundle/
\.DS_Store
.DS_Store
.Rproj.user
.Rhistory
.Rprofile
*.o
*.so
/src-i386/
/src-x86_64/
shinyapps/
README.html

27
.travis.yml Normal file
View File

@@ -0,0 +1,27 @@
# it is not really python, but there is no R support on Travis CI yet
language: python
# environment variables
env:
- R_LIBS_USER=~/R R_MY_PKG="$(basename $TRAVIS_REPO_SLUG)"
# install dependencies
install:
- sudo apt-add-repository -y "deb http://cran.rstudio.com/bin/linux/ubuntu `lsb_release -cs`/"
- sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E084DAB9
- sudo apt-add-repository -y ppa:marutter/c2d4u
- sudo apt-get update
- sudo apt-get install r-base-dev r-cran-shiny r-cran-cairo r-cran-markdown
- "[ ! -d ~/R ] && mkdir ~/R"
- Rscript -e "install.packages(c('xtable'), repos = 'http://cran.rstudio.org')"
- Rscript -e "install.packages('knitr', repos = c('http://rforge.net', 'http://cran.rstudio.org'))"
- Rscript -e "install.packages('$R_MY_PKG', dep = TRUE, repos = 'http://cran.rstudio.org')"
# run tests
script:
- cd ..; rm -f *.tar.gz; R CMD build $R_MY_PKG
- R CMD check $R_MY_PKG*.tar.gz --no-manual
after_failure:
- cat $R_MY_PKG.Rcheck/00install.out || true
- cat $R_MY_PKG.Rcheck/00check.log || true

64
DESCRIPTION Normal file
View File

@@ -0,0 +1,64 @@
Package: shiny
Type: Package
Title: Web Application Framework for R
Version: 0.9.1.9008
Date: 2014-03-19
Author: RStudio, Inc.
Maintainer: Winston Chang <winston@rstudio.com>
Description: Shiny makes it incredibly easy to build interactive web
applications with R. Automatic "reactive" binding between inputs and
outputs and extensive pre-built widgets make it possible to build
beautiful, responsive, and powerful applications with minimal effort.
License: GPL-3
Depends:
R (>= 2.14.1),
methods
Imports:
tools,
utils,
httpuv (>= 1.2.0),
caTools,
RJSONIO,
xtable,
digest,
htmltools (>= 0.2.4)
Suggests:
datasets,
Cairo (>= 1.5-5),
testthat,
knitr (>= 1.6),
markdown
URL: http://www.rstudio.com/shiny/
BugReports: https://github.com/rstudio/shiny/issues
Roxygen: list(wrap = FALSE)
Collate:
'app.R'
'bootstrap-layout.R'
'map.R'
'globals.R'
'utils.R'
'bootstrap.R'
'cache.R'
'fileupload.R'
'graph.R'
'hooks.R'
'html-deps.R'
'htmltools.R'
'imageutils.R'
'jqueryui.R'
'middleware-shiny.R'
'middleware.R'
'priorityqueue.R'
'react.R'
'reactive-domains.R'
'reactives.R'
'run-url.R'
'server.R'
'shiny.R'
'shinyui.R'
'shinywrappers.R'
'showcase.R'
'slider.R'
'tar.R'
'timer.R'
'update-input.R'

View File

@@ -1,5 +0,0 @@
source 'https://rubygems.org'
gem 'em-websocket'
gem 'eventmachine_httpserver'
gem 'json'

View File

@@ -1,18 +0,0 @@
GEM
remote: https://rubygems.org/
specs:
addressable (2.2.8)
em-websocket (0.3.6)
addressable (>= 2.1.1)
eventmachine (>= 0.12.9)
eventmachine (0.12.10)
eventmachine_httpserver (0.2.1)
json (1.7.3)
PLATFORMS
ruby
DEPENDENCIES
em-websocket
eventmachine_httpserver
json

185
NAMESPACE Normal file
View File

@@ -0,0 +1,185 @@
# Generated by roxygen2 (4.0.1): do not edit by hand
S3method("$",reactivevalues)
S3method("$",shinyoutput)
S3method("$<-",reactivevalues)
S3method("$<-",shinyoutput)
S3method("[",reactivevalues)
S3method("[",shinyoutput)
S3method("[<-",reactivevalues)
S3method("[<-",shinyoutput)
S3method("[[",reactivevalues)
S3method("[[",shinyoutput)
S3method("[[<-",reactivevalues)
S3method("[[<-",shinyoutput)
S3method("names<-",reactivevalues)
S3method(as.list,reactivevalues)
S3method(as.shiny.appobj,character)
S3method(as.shiny.appobj,list)
S3method(as.shiny.appobj,shiny.appobj)
S3method(as.tags,shiny.render.function)
S3method(names,reactivevalues)
S3method(print,reactive)
S3method(print,shiny.appobj)
S3method(str,reactivevalues)
export(HTML)
export(a)
export(absolutePanel)
export(actionButton)
export(actionLink)
export(addResourcePath)
export(animationOptions)
export(as.shiny.appobj)
export(basicPage)
export(bootstrapPage)
export(br)
export(checkboxGroupInput)
export(checkboxInput)
export(code)
export(column)
export(conditionalPanel)
export(dataTableOutput)
export(dateInput)
export(dateRangeInput)
export(div)
export(downloadButton)
export(downloadHandler)
export(downloadLink)
export(em)
export(exprToFunction)
export(fileInput)
export(fixedPage)
export(fixedPanel)
export(fixedRow)
export(flowLayout)
export(fluidPage)
export(fluidRow)
export(getDefaultReactiveDomain)
export(h1)
export(h2)
export(h3)
export(h4)
export(h5)
export(h6)
export(headerPanel)
export(helpText)
export(hr)
export(htmlOutput)
export(icon)
export(imageOutput)
export(img)
export(includeCSS)
export(includeHTML)
export(includeMarkdown)
export(includeScript)
export(includeText)
export(inputPanel)
export(installExprFunction)
export(invalidateLater)
export(is.reactive)
export(is.reactivevalues)
export(is.singleton)
export(isolate)
export(knit_print.shiny.appobj)
export(knit_print.shiny.render.function)
export(mainPanel)
export(makeReactiveBinding)
export(markRenderFunction)
export(maskReactiveContext)
export(navbarMenu)
export(navbarPage)
export(navlistPanel)
export(need)
export(numericInput)
export(observe)
export(onReactiveDomainEnded)
export(outputOptions)
export(p)
export(pageWithSidebar)
export(parseQueryString)
export(plotOutput)
export(plotPNG)
export(pre)
export(radioButtons)
export(reactive)
export(reactiveFileReader)
export(reactivePlot)
export(reactivePoll)
export(reactivePrint)
export(reactiveTable)
export(reactiveText)
export(reactiveTimer)
export(reactiveUI)
export(reactiveValues)
export(reactiveValuesToList)
export(registerInputHandler)
export(removeInputHandler)
export(renderDataTable)
export(renderImage)
export(renderPlot)
export(renderPrint)
export(renderTable)
export(renderText)
export(renderUI)
export(repeatable)
export(runApp)
export(runExample)
export(runGist)
export(runGitHub)
export(runUrl)
export(selectInput)
export(selectizeInput)
export(shinyApp)
export(shinyAppDir)
export(shinyServer)
export(shinyUI)
export(showReactLog)
export(sidebarLayout)
export(sidebarPanel)
export(singleton)
export(sliderInput)
export(span)
export(splitLayout)
export(stopApp)
export(strong)
export(submitButton)
export(tabPanel)
export(tableOutput)
export(tabsetPanel)
export(tag)
export(tagAppendAttributes)
export(tagAppendChild)
export(tagAppendChildren)
export(tagList)
export(tagSetChildren)
export(tags)
export(textInput)
export(textOutput)
export(titlePanel)
export(uiOutput)
export(updateCheckboxGroupInput)
export(updateCheckboxInput)
export(updateDateInput)
export(updateDateRangeInput)
export(updateNumericInput)
export(updateRadioButtons)
export(updateSelectInput)
export(updateSelectizeInput)
export(updateSliderInput)
export(updateTabsetPanel)
export(updateTextInput)
export(validate)
export(validateCssUnit)
export(verbatimTextOutput)
export(verticalLayout)
export(wellPanel)
export(withMathJax)
export(withReactiveDomain)
export(withTags)
import(RJSONIO)
import(caTools)
import(digest)
import(htmltools)
import(httpuv)
import(methods)
import(xtable)

573
NEWS Normal file
View File

@@ -0,0 +1,573 @@
shiny 0.9.1.9XXX
--------------------------------------------------------------------------------
* BREAKING CHANGE: By default, observers now terminate themselves if they were
created during a session and that session ends. See ?domains for more details.
* Most inputs can now accept `NULL` label values to omit the label altogether.
* New `actionLink` input control; like `actionButton`, but with the appearance
of a normal link.
* `renderPlot` now calls `print` on its result if it's visible (i.e. no more
explicit `print()` required for ggplot2).
* Added `maskReactiveContext` function. It blocks the current reactive context,
to evaluate expressions that shouldn't use reactive sources directly. (This
should not be commonly needed.)
* Added `flowLayout`, `splitLayout`, and `inputPanel` functions for putting UI
elements side by side. `flowPanel` lays out its children in a left-to-right,
top-to-bottom arrangement. `splitLayout` evenly divides its horizontal space
among its children (or unevenly divides if `cellWidths` argument is provided).
`inputPanel` is like `flowPanel`, but with a light grey background, and is
intended to be used to encapsulate small input controls wherever vertical
space is at a premium.
* `sliderInput` and `selectizeInput`/`selectInput` now use a standard horizontal
size instead of filling up all available horizontal space.
* Fixed a bug of renderDataTable() when the data object only has 1 row and 1
column. (Thanks, ZJ Dai, #429)
* `renderPrint` gained a new argument 'width' to control the width of the text
output, e.g. renderPrint({mtcars}, width = 40).
* Fixed #220: the zip file for a directory created by some programs may not have
the directory name as its first entry, in which case runUrl() can fail. (#220)
shiny 0.9.1
--------------------------------------------------------------------------------
* Fixed warning 'Error in Context$new : could not find function "loadMethod"'
that was happening to dependent packages on "R CMD check".
shiny 0.9.0
--------------------------------------------------------------------------------
* BREAKING CHANGE: Added a `host` parameter to runApp() and runExample(),
which defaults to the shiny.host option if it is non-NULL, or "127.0.0.1"
otherwise. This means that by default, Shiny applications can only be
accessed on the same machine from which they are served. To allow other
clients to connect, as in previous versions of Shiny, use "0.0.0.0"
(or the IP address of one of your network interfaces, if you care to be
explicit about it).
* Added a new function `selectizeInput()` to use the JavaScript library
selectize.js (https://github.com/brianreavis/selectize.js), which extends
the basic select input in many aspects.
* The `selectInput()` function also gained a new argument `selectize = TRUE`
to makes use of selectize.js by default. If you want to revert back to the
original select input, you have to call selectInput(..., selectize = FALSE).
* Added Showcase mode, which displays the R code for an app right in the app
itself. You can invoke Showcase mode by passing `display.mode="showcase"`
to the `runApp()` function. Or, if an app is designed to run in Showcase
mode by default, add a DESCRIPTION file in the app dir with Title, Author,
and License fields; with "Type: Shiny"; and with "DisplayMode: Showcase".
* Upgraded to Bootstrap 2.3.2 and jQuery 1.11.0.
* Make `tags$head()` and `singleton()` behave correctly when used with
`renderUI()` and `uiOutput()`. Previously, "hoisting content to the head"
and "only rendering items a single time" were features that worked only
when the page was initially loading, not in dynamic rendering.
* Files are now sourced with the `keep.source` option, to help with debugging
and profiling.
* Support user-defined input parsers for data coming in from JavaScript using
the parseShinyInput method.
* Fixed the bug #299: renderDataTable() can deal with 0-row data frames now.
(reported by Harlan Harris)
* Added `navbarPage()` and `navbarMenu()` functions to create applications
with multiple top level panels.
* Added `navlistPanel()` function to create layouts with a a bootstrap
navlist on the left and tabPanels on the right
* Added `type` parameter to `tabsetPanel()` to enable the use of pill
style tabs in addition to the standard ones.
* Added `position` paramter to `tabsetPanel()` to enable positioning of tabs
above, below, left, or right of tab content.
* Added `fluidPage()` and `fixedPage()` functions as well as related row and
column layout functions for creating arbitrary bootstrap grid layouts.
* Added `hr()` builder function for creating horizontal rules.
* Automatically concatenate duplicate attributes in tag definitions
* Added `responsive` parameter to page building functions for opting-out of
bootstrap responsive css.
* Added `theme` parameter to page building functions for specifying alternate
bootstrap css styles.
* Added `icon()` function for embedding icons from the
[font awesome](http://fontawesome.io/) icon library
* Added `makeReactiveBinding` function to turn a "regular" variable into a
reactive one (i.e. reading the variable makes the current reactive context
dependent on it, and setting the variable is a source of reactivity).
* Added a function `withMathJax()` to include the MathJax library in an app.
* The argument `selected` in checkboxGroupInput(), selectInput(), and
radioButtons() refers to the value(s) instead of the name(s) of the
argument `choices` now. For example, the value of the `selected` argument
in selectInput(..., choices = c('Label 1' = 'x1', 'Label 2' = 'x2'),
selected = 'Label 2') must be updated to 'x2', although names/labels will
be automatically converted to values internally for backward
compatibility. The same change applies to updateCheckboxGroupInput(),
updateSelectInput(), and updateRadioButtons() as well. (#340)
* Now it is possible to only update the value of a checkbox group, select input,
or radio buttons using the `selected` argument without providing the
`choices` argument in updateCheckboxGroupInput(), updateSelectInput(), and
updateRadioButtons(), respectively. (#340)
* Added `absolutePanel` and `fixedPanel` functions for creating absolute-
and fixed-position panels. They can be easily made user-draggable by
specifying `draggable = TRUE`.
* For the `options` argument of the function `renderDataTable()`, we can
pass literal JavaScript code to the DataTables library via `I()`. This
makes it possible to use any JavaScript object in the options, e.g. a
JavaScript function (which is not supported in JSON). See
`?renderDataTable` for details and examples.
* DataTables also works under IE8 now.
* Fixed a bug in DataTables pagination when searching is turned on, which
caused failures for matrices as well as empty rows when displaying data
frames using renderDataTable().
* The `options` argument in `renderDataTable()` can also take a function
that returns a list. This makes it possible to use reactive values in the
options. (#392)
* `renderDataTable()` respects more DataTables options now: (1) either
bPaginate = FALSE or iDisplayLength = -1 will disable pagination (i.e. all
rows are returned from the data); besides, this means we can also use -1
in the length menu, e.g. aLengthMenu = list(c(10, 30, -1), list(10, 30,
'All')); (2) we can disable searching for individual columns through the
bSearchable option, e.g. aoColumns = list(list(bSearchable = FALSE),
list(bSearchable = TRUE),...) (the search box for the first column is
hidden); (3) we can turn off searching entirely (for both global searching
and individual columns) using the option bFilter = FALSE.
* Added an argument `callback` in `renderDataTable()` so that a custom
JavaScript function can be applied to the DataTable object. This makes it
much easier to use DataTables plug-ins.
* For numeric columns in a DataTable, the search boxes support lower and
upper bounds now: a search query of the form "lower,upper" (without
quotes) indicates the limits [lower, upper]. For a column X, this means
the rows corresponding to X >= lower & X <= upper are returned. If we omit
either the lower limit or the upper limit, only the other limit will be
used, e.g. ",upper" means X <= upper.
* `updateNumericInput(value)` tries to preserve numeric precision by avoiding
scientific notation when possible, e.g. 102145 is no longer rounded to
1.0214e+05 = 102140. (Thanks, Martin Loos. #401)
* `sliderInput()` no longer treats a label wrapped in HTML() as plain text,
e.g. the label in sliderInput(..., label = HTML('<em>A Label</em>')) will
not be escaped any more. (#119)
* Fixed #306: the trailing slash in a path could fail `addResourcePath()`
under Windows. (Thanks, ZJ Dai)
* Dots are now legal characters for inputId/outputId. (Thanks, Kevin
Lindquist. #358)
shiny 0.8.0
--------------------------------------------------------------------------------
* Debug hooks are registered on all user-provided functions and (reactive)
expressions (e.g., in renderPlot()), which makes it possible to set
breakpoints in these functions using the latest version of the RStudio
IDE, and the RStudio visual debugging tools can be used to debug Shiny
apps. Internally, the registration is done via installExprFunction(),
which is a new function introduced in this version to replace
exprToFunction() so that the registration can be automatically done.
* Added a new function renderDataTable() to display tables using the
JavaScript library DataTables. It includes basic features like pagination,
searching (global search or search by individual columns), sorting (by
single or multiple columns). All these features are implemented on the R
side; for example, we can use R regular expressions for searching.
Besides, it also uses the Bootstrap CSS style. See the full
documentation and examples in the tutorial:
http://rstudio.github.io/shiny/tutorial/#datatables
* Added a new option `shiny.error` which can take a function as an error
handler. It is called when an error occurs in an app (in user-provided
code), e.g., after we set options(shiny.error = recover), we can enter a
specified environment in the call stack to debug our code after an error
occurs.
* The argument `launch.browser` in runApp() can also be a function,
which takes the URL of the shiny app as its input value.
* runApp() uses a random port between 3000 and 8000 instead of 8100 now. It
will try up to 20 ports in case certain ports are not available.
* Fixed a bug for conditional panels: the value `input.id` in the condition
was not correctly retrieved when the input widget had a type, such as
numericInput(). (reported by Jason Bryer)
* Fixed two bugs in plotOutput(); clickId and hoverId did not give correct
coordinates in Firefox, or when the axis limits of the plot were changed.
(reported by Chris Warth and Greg D)
* The minimal required version for the httpuv package was increased to 1.2
(on CRAN now).
shiny 0.7.0
--------------------------------------------------------------------------------
* Stopped sending websocket subprotocol. This fixes a compatibility issue with
Google Chrome 30.
* The `input` and `output` objects are now also accessible via `session$input`
and `session$output`.
* Added click and hover events for static plots; see `?plotOutput` for details.
* Added optional logging of the execution states of a reactive program, and
tools for visualizing the log data. To use, start a new R session and call
`options(shiny.reactlog=TRUE)`. Then launch a Shiny app and interact with it.
Press Ctrl+F3 (or for Mac, Cmd+F3) in the browser to launch an interactive
visualization of the reactivity that has occurred. See `?showReactLog` for
more information.
* Added `includeScript()` and `includeCSS()` functions.
* Reactive expressions now have class="reactive" attribute. Also added
`is.reactive()` and `is.reactivevalues()` functions.
* New `stopApp()` function, which stops an app and returns a value to the caller
of `runApp()`.
* Added the `shiny.usecairo` option, which can be used to tell Shiny not to use
Cairo for PNG output even when it is installed. (Defaults to `TRUE`.)
* Speed increases for `selectInput()` and `radioButtons()`, and their
corresponding updater functions, for when they have many options.
* Added `tagSetChildren()` and `tagAppendChildren()` functions.
* The HTTP request object that created the websocket is now accessible from the
`session` object, as `session$request`. This is a Rook-like request
environment that can be used to access HTTP headers, among other things.
(Note: When running in a Shiny Server environment, the request will reflect
the proxy HTTP request that was made from the Shiny Server process to the R
process, not the request that was made from the web browser to Shiny Server.)
* Fix `getComputedStyle` issue, for IE8 browser compatibility (#196). Note:
Shiny Server is still required for IE8/9 compatibility.
* Add shiny.sharedSecret option, to require the HTTP header Shiny-Shared-Secret
to be set to the given value.
shiny 0.6.0
--------------------------------------------------------------------------------
* `tabsetPanel()` can be directed to start with a specific tab selected.
* Fix bug where multiple file uploads with 3 or more files result in incorrect
data.
* Add `withTags()` function.
* Add dateInput and dateRangeInput.
* `shinyServer()` now takes an optional `session` argument, which is used for
communication with the session object.
* Add functions to update values of existing inputs on a page, instead of
replacing them entirely.
* Allow listening on domain sockets.
* Added `actionButton()` to Shiny.
* The server can now send custom JSON messages to the client. On the client
side, functions can be registered to handle these messages.
* Callbacks can be registered to be called at the end of a client session.
* Add ability to set priority of observers and outputs. Each priority level
gets its own queue.
* Fix bug where the presence of a submit button would prevent sending of
metadata until the button was clicked.
* `reactiveTimer()` and `invalidateLater()` by default no longer invalidate
reactive objects after the client session has closed.
* Shiny apps can be run without a server.r and ui.r file.
shiny 0.5.0
--------------------------------------------------------------------------------
* Switch from websockets package for handling websocket connections to httpuv.
* New method for detecting hidden output objects. Instead of checking that
height and width are 0, it checks that the object or any ancestor in the DOM
has style display:none.
* Add `clientData` reactive values object, which carries information about the
client. This includes the hidden status of output objects, height/width plot
output objects, and the URL of the browser.
* Add `parseQueryString()` function.
* Add `renderImage()` function for sending arbitrary image files to the client,
and its counterpart, `imageOutput()`.
* Add support for high-resolution (Retina) displays.
* Fix bug #55, where `renderTable()` would throw error with an empty data frame.
shiny 0.4.1
--------------------------------------------------------------------------------
* Fix bug where width and height weren't passed along properly from
`reactivePlot` to `renderPlot`.
* Fix bug where infinite recursion would happen when `reactivePlot` was passed
a function for width or height.
shiny 0.4.0
--------------------------------------------------------------------------------
* Added suspend/resume capability to observers.
* Output objects are automatically suspended when they are hidden on the user's
web browser.
* `runGist()` accepts GitHub's new URL format, which includes the username.
* `reactive()` and `observe()` now take expressions instead of functions.
* `reactiveText()`, `reactivePlot()`, and so on, have been renamed to
`renderText()`, `renderPlot()`, etc. They also now take expressions instead
of functions.
* Fixed a bug where empty values in a numericInput were sent to the R process
as 0. They are now sent as NA.
shiny 0.3.1
--------------------------------------------------------------------------------
* Fix issue #91: bug where downloading files did not work.
* Add [[<- operator for shinyoutput object, making it possible to assign values
with `output[['plot1']] <- ...`.
* Reactive functions now preserve the visible/invisible state of their returned
values.
shiny 0.3.0
--------------------------------------------------------------------------------
* Reactive functions are now evaluated lazily.
* Add `reactiveValues()`.
* Using `as.list()` to convert a reactivevalues object (like `input`) to a list
is deprecated. The new function `reactiveValuesToList()` should be used
instead.
* Add `isolate()`. This function is used for accessing reactive functions,
without them invalidating their parent contexts.
* Fix issue #58: bug where reactive functions are not re-run when all items in
a checkboxGroup are unchecked.
* Fix issue #71, where `reactiveTable()` would return blank if the first
element of a data frame was NA.
* In `plotOutput`, better validation for CSS units when specifying width and
height.
* `reactivePrint()` no longer displays invisible output.
* `reactiveText()` no longer displays printed output, only the return value
from a function.
* The `runGitHub()` and `runUrl()` functions have been added, for running
Shiny apps from GitHub repositories and zip/tar files at remote URLs.
* Fix issue #64, where pressing Enter in a textbox would cause a form to
submit.
shiny 0.2.4
--------------------------------------------------------------------------------
* `runGist` has been updated to use the new download URLs from
https://gist.github.com.
* Shiny now uses `CairoPNG()` for output, when the Cairo package is available.
This provides better-looking output on Linux and Windows.
shiny 0.2.3
--------------------------------------------------------------------------------
* Ignore request variables for routing purposes
shiny 0.2.2
--------------------------------------------------------------------------------
* Fix CRAN warning (assigning to global environment)
shiny 0.2.1
--------------------------------------------------------------------------------
* [BREAKING] Modify API of `downloadHandler`: The `content` function now takes
a file path, not writable connection, as an argument. This makes it much
easier to work with APIs that only write to file paths, not connections.
shiny 0.2.0
--------------------------------------------------------------------------------
* Fix subtle name resolution bug--the usual symptom being S4 methods not being
invoked correctly when called from inside of ui.R or server.R
shiny 0.1.14
--------------------------------------------------------------------------------
* Fix slider animator, which broke in 0.1.10
shiny 0.1.13
--------------------------------------------------------------------------------
* Fix temp file leak in reactivePlot
shiny 0.1.12
--------------------------------------------------------------------------------
* Fix problems with runGist on Windows
* Add feature for on-the-fly file downloads (e.g. CSV data, PDFs)
* Add CSS hooks for app-wide busy indicators
shiny 0.1.11
--------------------------------------------------------------------------------
* Fix input binding with IE8 on Shiny Server
* Fix issue #41: reactiveTable should allow print options too
* Allow dynamic sizing of reactivePlot (i.e. using a function instead of a fixed
value)
shiny 0.1.10
--------------------------------------------------------------------------------
* Support more MIME types when serving out of www
* Fix issue #35: Allow modification of untar args
* headerPanel can take an explicit window title parameter
* checkboxInput uses correct attribute `checked` instead of `selected`
* Fix plot rendering with IE8 on Shiny Server
shiny 0.1.9
--------------------------------------------------------------------------------
* Much less flicker when updating plots
* More customizable error display
* Add `includeText`, `includeHTML`, and `includeMarkdown` functions for putting
text, HTML, and Markdown content from external files in the application's UI.
shiny 0.1.8
--------------------------------------------------------------------------------
* Add `runGist` function for conveniently running a Shiny app that is published
on gist.github.com.
* Fix issue #27: Warnings cause reactive functions to stop executing.
* The server.R and ui.R filenames are now case insensitive.
* Add `wellPanel` function for creating inset areas on the page.
* Add `bootstrapPage` function for creating new Bootstrap based
layouts from scratch.
shiny 0.1.7
--------------------------------------------------------------------------------
* Fix issue #26: Shiny.OutputBindings not correctly exported.
* Add `repeatable` function for making easily repeatable versions of random
number generating functions.
* Transcode JSON into UTF-8 (prevents non-ASCII reactivePrint values from
causing errors on Windows).
shiny 0.1.6
--------------------------------------------------------------------------------
* Import package dependencies, instead of attaching them (with the exception of
websockets, which doesn't currently work unless attached).
* conditionalPanel was animated, now it is not.
* bindAll was not correctly sending initial values to the server; fixed.
shiny 0.1.5
--------------------------------------------------------------------------------
* BREAKING CHANGE: JS APIs Shiny.bindInput and Shiny.bindOutput removed and
replaced with Shiny.bindAll; Shiny.unbindInput and Shiny.unbindOutput removed
and replaced with Shiny.unbindAll.
* Add file upload support (currently only works with Chrome and Firefox). Use
a normal HTML file input, or call the `fileInput` UI function.
* Shiny.unbindOutputs did not work, now it does.
* Generally improved robustness of dynamic input/output bindings.
* Add conditionalPanel UI function to allow showing/hiding UI based on a JS
expression; for example, whether an input is a particular value. Also works in
raw HTML (add the `data-display-if` attribute to the element that should be
shown/hidden).
* htmlOutput (CSS class `shiny-html-output`) can contain inputs and outputs.
shiny 0.1.4
--------------------------------------------------------------------------------
* Allow Bootstrap tabsets to act as reactive inputs; their value indicates which
tab is active
* Upgrade to Bootstrap 2.1
* Add `checkboxGroupInput` control, which presents a list of checkboxes and
returns a vector of the selected values
* Add `addResourcePath`, intended for reusable component authors to access CSS,
JavaScript, image files, etc. from their package directories
* Add Shiny.bindInputs(scope), .unbindInputs(scope), .bindOutputs(scope), and
.unbindOutputs(scope) JS API calls to allow dynamic binding/unbinding of HTML
elements
shiny 0.1.3
--------------------------------------------------------------------------------
* Introduce Shiny.inputBindings.register JS API and InputBinding class, for
creating custom input controls
* Add `step` parameter to numericInput
* Read names of input using `names(input)`
* Access snapshot of input as a list using `as.list(input)`
* Fix issue #10: Plots in tabsets not rendered
shiny 0.1.2
--------------------------------------------------------------------------------
Initial private beta release!

288
R/app.R Normal file
View File

@@ -0,0 +1,288 @@
# TODO: Subapp global.R
#' Create a Shiny app object
#'
#' These functions create Shiny app objects from either an explicit UI/server
#' pair (\code{shinyApp}), or by passing the path of a directory that
#' contains a Shiny app (\code{shinyAppDir}). You generally shouldn't need to
#' use these functions to create/run applications; they are intended for
#' interoperability purposes, such as embedding Shiny apps inside a \pkg{knitr}
#' document.
#'
#' @param ui The UI definition of the app (for example, a call to
#' \code{fluidPage()} with nested controls)
#' @param server A server function
#' @param onStart A function that will be called before the app is actually run.
#' This is only needed for \code{shinyAppObj}, since in the \code{shinyAppDir}
#' case, a \code{global.R} file can be used for this purpose.
#' @param options Named options that should be passed to the `runApp` call. You
#' can also specify \code{width} and \code{height} parameters which provide a
#' hint to the embedding environment about the ideal height/width for the app.
#' @param uiPattern A regular expression that will be applied to each \code{GET}
#' request to determine whether the \code{ui} should be used to handle the
#' request. Note that the entire request path must match the regular
#' expression in order for the match to be considered successful.
#' @return An object that represents the app. Printing the object will run the
#' app.
#'
#' @examples
#' \dontrun{
#' shinyApp(
#' ui = fluidPage(
#' numericInput("n", "n", 1),
#' plotOutput("plot")
#' ),
#' server = function(input, output) {
#' output$plot <- renderPlot( plot(head(cars, input$n)) )
#' },
#' options=list(launch.browser = rstudio::viewer)
#' )
#'
#' shinyAppDir(system.file("examples/01_hello", package="shiny"))
#' }
#'
#' @export
shinyApp <- function(ui, server, onStart=NULL, options=list(), uiPattern="/") {
# Ensure that the entire path is a match
uiPattern <- sprintf("^%s$", uiPattern)
httpHandler <- function(req) {
if (!identical(req$REQUEST_METHOD, 'GET'))
return(NULL)
if (!isTRUE(grepl(uiPattern, req$PATH_INFO)))
return(NULL)
textConn <- textConnection(NULL, "w")
on.exit(close(textConn))
uiValue <- if (is.function(ui)) {
if (length(formals(ui)) > 0)
ui(req)
else
ui()
} else {
ui
}
if (is.null(uiValue))
return(NULL)
renderPage(uiValue, textConn)
html <- paste(textConnectionValue(textConn), collapse='\n')
return(httpResponse(200, content=html))
}
serverFuncSource <- function() {
server
}
structure(
list(
httpHandler = httpHandler,
serverFuncSource = serverFuncSource,
onStart = onStart,
options = options),
class = "shiny.appobj"
)
}
#' @rdname shinyApp
#' @param appDir Path to directory that contains a Shiny app (i.e. a server.R
#' file and either ui.R or www/index.html)
#' @export
shinyAppDir <- function(appDir, options=list()) {
# Most of the complexity here comes from needing to hot-reload if the .R files
# change on disk, or are created, or are removed.
if (!file.exists(appDir)) {
stop("No Shiny application exists at the path \"", appDir, "\"")
}
# In case it's a relative path, convert to absolute (so we're not adversely
# affected by future changes to the path)
appDir <- normalizePath(appDir, mustWork = TRUE)
# uiHandlerSource is a function that returns an HTTP handler for serving up
# ui.R as a webpage. The "cachedFuncWithFile" call makes sure that the closure
# we're creating here only gets executed when ui.R's contents change.
uiHandlerSource <- cachedFuncWithFile(appDir, "ui.R", case.sensitive = FALSE,
function(uiR) {
if (file.exists(uiR)) {
# If ui.R contains a call to shinyUI (which sets .globals$ui), use that.
# If not, then take the last expression that's returned from ui.R.
.globals$ui <- NULL
on.exit(.globals$ui <- NULL, add = FALSE)
ui <- source(uiR,
local = new.env(parent = globalenv()),
keep.source = TRUE)$value
if (!is.null(.globals$ui)) {
ui <- .globals$ui[[1]]
}
return(uiHttpHandler(ui))
} else {
return(function(req) NULL)
}
}
)
uiHandler <- function(req) {
uiHandlerSource()(req)
}
wwwDir <- file.path.ci(appDir, "www")
fallbackWWWDir <- system.file("www-dir", package = "shiny")
serverSource <- cachedFuncWithFile(appDir, "server.R", case.sensitive = FALSE,
function(serverR) {
# If server.R contains a call to shinyServer (which sets .globals$server),
# use that. If not, then take the last expression that's returned from
# server.R.
.globals$server <- NULL
on.exit(.globals$server <- NULL, add = TRUE)
result <- source(
serverR,
local = new.env(parent = globalenv()),
keep.source = TRUE
)$value
if (!is.null(.globals$server)) {
result <- .globals$server[[1]]
}
return(result)
}
)
# This function stands in for the server function, and reloads the
# real server function as necessary whenever server.R changes
serverFuncSource <- function() {
serverFunction <- serverSource()
if (is.null(serverFunction)) {
return(function(input, output) NULL)
} else if (is.function(serverFunction)) {
# This is what we normally expect; run the server function
return(serverFunction)
} else {
stop("server.R returned an object of unexpected type: ",
typeof(serverFunction))
}
}
oldwd <- NULL
onStart <- function() {
oldwd <<- getwd()
setwd(appDir)
if (file.exists(file.path.ci(appDir, "global.R")))
source(file.path.ci(appDir, "global.R"), keep.source = TRUE)
}
onEnd <- function() {
setwd(oldwd)
}
structure(
list(
httpHandler = joinHandlers(c(uiHandler, wwwDir, fallbackWWWDir)),
serverFuncSource = serverFuncSource,
onStart = onStart,
onEnd = onEnd,
options = options),
class = "shiny.appobj"
)
}
#' @rdname shinyApp
#' @param x Object to convert to a Shiny app.
#' @export
as.shiny.appobj <- function(x) {
UseMethod("as.shiny.appobj", x)
}
#' @rdname shinyApp
#' @export
as.shiny.appobj.shiny.appobj <- function(x) {
x
}
#' @rdname shinyApp
#' @export
as.shiny.appobj.list <- function(x) {
shinyApp(ui = x$ui, server = x$server)
}
#' @rdname shinyApp
#' @export
as.shiny.appobj.character <- function(x) {
shinyAppDir(x)
}
#' @rdname shinyApp
#' @param ... Additional parameters to be passed to print.
#' @export
print.shiny.appobj <- function(x, ...) {
opts <- x$options %OR% list()
opts <- opts[names(opts) %in%
c("port", "launch.browser", "host", "quiet", "display.mode")]
args <- c(list(x), opts)
do.call(runApp, args)
}
#' Knitr S3 methods
#'
#' These S3 methods are necessary to help Shiny applications and UI chunks embed
#' themselves in knitr/rmarkdown documents.
#'
#' @name knitr_methods
#' @param x Object to knit_print
#' @param ... Additional knit_print arguments
NULL
#' @rdname knitr_methods
#' @export
knit_print.shiny.appobj <- function(x, ...) {
opts <- x$options %OR% list()
width <- if (is.null(opts$width)) "100%" else opts$width
height <- if (is.null(opts$height)) "400" else opts$height
shiny_warning <- NULL
# if there's an R Markdown runtime option set but it isn't set to Shiny, then
# emit a warning indicating the runtime is inappropriate for this object
runtime <- knitr::opts_knit$get("rmarkdown.runtime")
if (!is.null(runtime) && runtime != "shiny") {
# note that the RStudio IDE checks for this specific string to detect Shiny
# applications in static document
shiny_warning <- list(structure(
"Shiny application in a static R Markdown document",
class = "rmd_warning"))
# create a box exactly the same dimensions as the Shiny app would have had
# (so the document continues to flow as it would have with the app), and
# display a diagnostic message
width <- validateCssUnit(width)
height <- validateCssUnit(height)
output <- tags$div(
style=paste("width:", width, "; height:", height, "; text-align: center;",
"box-sizing: border-box;", "-moz-box-sizing: border-box;",
"-webkit-box-sizing: border-box;"),
class="muted well",
"Shiny applications not supported in static R Markdown documents")
}
else {
path <- addSubApp(x)
output <- tags$iframe(src=path, width=width, height=height,
class="shiny-frame")
}
# If embedded Shiny apps ever have JS/CSS dependencies (like pym.js) we'll
# need to grab those and put them in meta, like in knit_print.shiny.tag. But
# for now it's not an issue, so just return the HTML and warning.
knitr::asis_output(htmlPreserve(format(output, indent=FALSE)),
meta = shiny_warning, cacheable = FALSE)
}
# Lets us use a nicer syntax in knitr chunks than literally
# calling output$value <- renderFoo(...) and fooOutput().
#' @rdname knitr_methods
#' @export
knit_print.shiny.render.function <- function(x, ...) {
output <- knitr::knit_print(tagList(x))
attr(output, "knit_cacheable") <- FALSE
output
}

421
R/bootstrap-layout.R Normal file
View File

@@ -0,0 +1,421 @@
#' Create a page with fluid layout
#'
#' Functions for creating fluid page layouts. A fluid page layout consists of
#' rows which in turn include columns. Rows exist for the purpose of making sure
#' their elements appear on the same line (if the browser has adequate width).
#' Columns exist for the purpose of defining how much horizontal space within a
#' 12-unit wide grid it's elements should occupy. Fluid pages scale their
#' components in realtime to fill all available browser width.
#'
#' @param ... Elements to include within the page
#' @param title The browser window title (defaults to the host URL of the page).
#' Can also be set as a side effect of the \code{\link{titlePanel}} function.
#' @param responsive \code{TRUE} to use responsive layout (automatically adapt
#' and resize page elements based on the size of the viewing device)
#' @param theme Alternative Bootstrap stylesheet (normally a css file within the
#' www directory). For example, to use the theme located at
#' \code{www/bootstrap.css} you would use \code{theme = "bootstrap.css"}.
#'
#' @return A UI defintion that can be passed to the \link{shinyUI} function.
#'
#' @details To create a fluid page use the \code{fluidPage} function and include
#' instances of \code{fluidRow} and \code{\link{column}} within it. As an
#' alternative to low-level row and column functions you can also use
#' higher-level layout functions like \code{\link{sidebarLayout}}.
#'
#' @note See the
#' \href{https://github.com/rstudio/shiny/wiki/Shiny-Application-Layout-Guide}{
#' Shiny-Application-Layout-Guide} for additional details on laying out fluid
#' pages.
#'
#' @seealso \code{\link{column}}, \code{\link{sidebarLayout}}
#'
#' @examples
#' shinyUI(fluidPage(
#'
#' # Application title
#' titlePanel("Hello Shiny!"),
#'
#' sidebarLayout(
#'
#' # Sidebar with a slider input
#' sidebarPanel(
#' sliderInput("obs",
#' "Number of observations:",
#' min = 0,
#' max = 1000,
#' value = 500)
#' ),
#'
#' # Show a plot of the generated distribution
#' mainPanel(
#' plotOutput("distPlot")
#' )
#' )
#' ))
#'
#' shinyUI(fluidPage(
#' title = "Hello Shiny!",
#' fluidRow(
#' column(width = 4,
#' "4"
#' ),
#' column(width = 3, offset = 2,
#' "3 offset 2"
#' )
#' )
#' ))
#'
#' @rdname fluidPage
#' @export
fluidPage <- function(..., title = NULL, responsive = TRUE, theme = NULL) {
bootstrapPage(div(class = "container-fluid", ...),
title = title,
responsive = responsive,
theme = theme)
}
#' @rdname fluidPage
#' @export
fluidRow <- function(...) {
div(class = "row-fluid", ...)
}
#' Create a page with a fixed layout
#'
#' Functions for creating fixed page layouts. A fixed page layout consists of
#' rows which in turn include columns. Rows exist for the purpose of making sure
#' their elements appear on the same line (if the browser has adequate width).
#' Columns exist for the purpose of defining how much horizontal space within a
#' 12-unit wide grid it's elements should occupy. Fixed pages limit their width
#' to 940 pixels on a typical display, and 724px or 1170px on smaller and larger
#' displays respectively.
#'
#' @param ... Elements to include within the container
#' @param title The browser window title (defaults to the host URL of the page)
#' @param responsive \code{TRUE} to use responsive layout (automatically adapt
#' and resize page elements based on the size of the viewing device)
#' @param theme Alternative Bootstrap stylesheet (normally a css file within the
#' www directory). For example, to use the theme located at
#' \code{www/bootstrap.css} you would use \code{theme = "bootstrap.css"}.
#'
#' @return A UI defintion that can be passed to the \link{shinyUI} function.
#'
#' @details To create a fixed page use the \code{fixedPage} function and include
#' instances of \code{fixedRow} and \code{\link{column}} within it. Note that
#' unlike \code{\link{fluidPage}}, fixed pages cannot make use of higher-level
#' layout functions like \code{sidebarLayout}, rather, all layout must be done
#' with \code{fixedRow} and \code{column}.
#'
#' @note See the
#' \href{https://github.com/rstudio/shiny/wiki/Shiny-Application-Layout-Guide}{
#' Shiny Application Layout Guide} for additional details on laying out fixed
#' pages.
#'
#' @seealso \code{\link{column}}
#'
#' @examples
#' shinyUI(fixedPage(
#' title = "Hello, Shiny!",
#' fixedRow(
#' column(width = 4,
#' "4"
#' ),
#' column(width = 3, offset = 2,
#' "3 offset 2"
#' )
#' )
#' ))
#'
#' @rdname fixedPage
#' @export
fixedPage <- function(..., title = NULL, responsive = TRUE, theme = NULL) {
bootstrapPage(div(class = "container", ...),
title = title,
responsive = responsive,
theme = theme)
}
#' @rdname fixedPage
#' @export
fixedRow <- function(...) {
div(class = "row", ...)
}
#' Create a column within a UI definition
#'
#' Create a column for use within a \code{\link{fluidRow}} or
#' \code{\link{fixedRow}}
#'
#' @param width The grid width of the column (must be between 1 and 12)
#' @param ... Elements to include within the column
#' @param offset The number of columns to offset this column from the end of the
#' previous column.
#'
#' @return A column that can be included within a
#' \code{\link{fluidRow}} or \code{\link{fixedRow}}.
#'
#'
#' @seealso \code{\link{fluidRow}}, \code{\link{fixedRow}}.
#'
#' @examples
#' fluidRow(
#' column(4,
#' sliderInput("obs", "Number of observations:",
#' min = 1, max = 1000, value = 500)
#' ),
#' column(8,
#' plotOutput("distPlot")
#' )
#' )
#'
#' fluidRow(
#' column(width = 4,
#' "4"
#' ),
#' column(width = 3, offset = 2,
#' "3 offset 2"
#' )
#' )
#' @export
column <- function(width, ..., offset = 0) {
if (!is.numeric(width) || (width < 1) || (width > 12))
stop("column width must be between 1 and 12")
colClass <- paste0("span", width)
if (offset > 0)
colClass <- paste0(colClass, " offset", offset)
div(class = colClass, ...)
}
#' Create a panel containing an application title.
#'
#' @param title An application title to display
#' @param windowTitle The title that should be displayed by the browser window.
#'
#' @details Calling this function has the side effect of including a
#' \code{title} tag within the head. You can also specify a page title
#' explicitly using the `title` parameter of the top-level page function.
#'
#'
#' @examples
#' titlePanel("Hello Shiny!")
#'
#' @export
titlePanel <- function(title, windowTitle=title) {
tagList(
tags$head(tags$title(windowTitle)),
h2(style = "padding: 10px 0px;", title)
)
}
#' Layout a sidebar and main area
#'
#' Create a layout with a sidebar and main area. The sidebar is displayed with a
#' distinct background color and typically contains input controls. The main
#' area occupies 2/3 of the horizontal width and typically contains outputs.
#'
#' @param sidebarPanel The \link{sidebarPanel} containing input controls
#' @param mainPanel The \link{mainPanel} containing outputs
#' @param position The position of the sidebar relative to the main area ("left"
#' or "right")
#' @param fluid \code{TRUE} to use fluid layout; \code{FALSE} to use fixed
#' layout.
#'
#' @examples
#' # Define UI
#' shinyUI(fluidPage(
#'
#' # Application title
#' titlePanel("Hello Shiny!"),
#'
#' sidebarLayout(
#'
#' # Sidebar with a slider input
#' sidebarPanel(
#' sliderInput("obs",
#' "Number of observations:",
#' min = 0,
#' max = 1000,
#' value = 500)
#' ),
#'
#' # Show a plot of the generated distribution
#' mainPanel(
#' plotOutput("distPlot")
#' )
#' )
#' ))
#'
#' @export
sidebarLayout <- function(sidebarPanel,
mainPanel,
position = c("left", "right"),
fluid = TRUE) {
# determine the order
position <- match.arg(position)
if (position == "left") {
firstPanel <- sidebarPanel
secondPanel <- mainPanel
}
else if (position == "right") {
firstPanel <- mainPanel
secondPanel <- sidebarPanel
}
# return as as row
if (fluid)
fluidRow(firstPanel, secondPanel)
else
fixedRow(firstPanel, secondPanel)
}
#' Lay out UI elements vertically
#'
#' Create a container that includes one or more rows of content (each element
#' passed to the container will appear on it's own line in the UI)
#'
#' @param ... Elements to include within the container
#' @param fluid \code{TRUE} to use fluid layout; \code{FALSE} to use fixed
#' layout.
#'
#' @seealso \code{\link{fluidPage}}, \code{\link{flowLayout}}
#'
#' @examples
#' shinyUI(fluidPage(
#' verticalLayout(
#' a(href="http://example.com/link1", "Link One"),
#' a(href="http://example.com/link2", "Link Two"),
#' a(href="http://example.com/link3", "Link Three")
#' )
#' ))
#' @export
verticalLayout <- function(..., fluid = TRUE) {
lapply(list(...), function(row) {
col <- column(12, row)
if (fluid)
fluidRow(col)
else
fixedRow(col)
})
}
#' Flow layout
#'
#' Lays out elements in a left-to-right, top-to-bottom arrangement. The elements
#' on a given row will be top-aligned with each other. This layout will not work
#' well with elements that have a percentage-based width (e.g. `plotOutput` at
#' its default setting of `width = "100%"`).
#'
#' @param ... Unnamed arguments will become child elements of the layout. Named
#' arguments will become HTML attributes on the outermost tag.
#' @param cellArgs Any additional attributes that should be used for each cell
#' of the layout.
#'
#' @seealso \code{\link{verticalLayout}}
#'
#' #' @examples
#' flowLayout(
#' numericInput("rows", "How many rows?", 5),
#' selectInput("letter", "Which letter?", LETTERS),
#' sliderInput("value", "What value?", 0, 100, 50)
#' )
#' @export
flowLayout <- function(..., cellArgs = list()) {
children <- list(...)
childIdx <- !nzchar(names(children) %OR% character(length(children)))
attribs <- children[!childIdx]
children <- children[childIdx]
do.call(tags$div, c(list(class = "shiny-flow-layout"),
attribs,
lapply(children, function(x) {
do.call(tags$div, c(cellArgs, list(x)))
})
))
}
#' Input panel
#'
#' A \code{\link{flowLayout}} with a grey border and light grey background,
#' suitable for wrapping inputs.
#'
#' @param ... Input controls or other HTML elements.
#'
#' @export
inputPanel <- function(...) {
div(class = "shiny-input-panel",
flowLayout(...)
)
}
#' Split layout
#'
#' Lays out elements horizontally, dividing the available horizontal space into
#' equal parts (by default).
#'
#' @param ... Unnamed arguments will become child elements of the layout. Named
#' arguments will become HTML attributes on the outermost tag.
#' @param cellWidths Character or numeric vector indicating the widths of the
#' individual cells. Recycling will be used if needed. Character values will
#' be interpreted as CSS lengths (see \code{\link{validateCssUnit}}), numeric
#' values as pixels.
#' @param cellArgs Any additional attributes that should be used for each cell
#' of the layout.
#'
#' #' @examples
#' # Equal sizing
#' splitLayout(
#' plotOutput("plot1"),
#' plotOutput("plot2")
#' )
#'
#' # Custom widths
#' splitLayout(cellWidths = c("25%", "75%"),
#' plotOutput("plot1"),
#' plotOutput("plot2")
#' )
#'
#' # All cells at 300 pixels wide, with cell padding
#' # and a border around everything
#' splitLayout(
#' style = "border: 1px solid silver;",
#' cellWidths = 300,
#' cellArgs = list(style = "padding: 6px"),
#' plotOutput("plot1"),
#' plotOutput("plot2"),
#' plotOutput("plot3")
#' )
#' @export
splitLayout <- function(..., cellWidths = NULL, cellArgs = list()) {
children <- list(...)
childIdx <- !nzchar(names(children) %OR% character(length(children)))
attribs <- children[!childIdx]
children <- children[childIdx]
count <- length(children)
if (length(cellWidths) == 0 || is.na(cellWidths)) {
cellWidths <- sprintf("%.3f%%", 100 / count)
}
cellWidths <- rep(cellWidths, length.out = count)
cellWidths <- sapply(cellWidths, validateCssUnit)
do.call(tags$div, c(list(class = "shiny-split-layout"),
attribs,
mapply(children, cellWidths, FUN = function(x, w) {
do.call(tags$div, c(
list(style = sprintf("width: %s;", w)),
cellArgs,
list(x)
))
}, SIMPLIFY = FALSE)
))
}

1768
R/bootstrap.R Normal file

File diff suppressed because it is too large Load Diff

80
R/cache.R Normal file
View File

@@ -0,0 +1,80 @@
# A context object for tracking a cache that needs to be dirtied when a set of
# files changes on disk. Each time the cache is dirtied, the set of files is
# cleared. Therefore, the set of files needs to be re-built each time the cached
# code executes. This approach allows for dynamic dependency graphs.
CacheContext <- setRefClass(
'CacheContext',
fields = list(
.dirty = 'logical',
.tests = 'list'
),
methods = list(
initialize = function() {
.dirty <<- TRUE
# List of functions that return TRUE if dirty
.tests <<- list()
},
addDependencyFile = function(file) {
if (.dirty)
return()
file <- normalizePath(file)
mtime <- file.info(file)$mtime
.tests <<- c(.tests, function() {
newMtime <- try(file.info(file)$mtime, silent=TRUE)
if (inherits(newMtime, 'try-error'))
return(TRUE)
return(!identical(mtime, newMtime))
})
invisible()
},
forceDirty = function() {
.dirty <<- TRUE
.tests <<- list()
invisible()
},
isDirty = function() {
if (.dirty)
return(TRUE)
for (test in .tests) {
if (test()) {
forceDirty()
return(TRUE)
}
}
return(FALSE)
},
reset = function() {
.dirty <<- FALSE
.tests <<- list()
},
with = function(func) {
oldCC <- .currentCacheContext$cc
.currentCacheContext$cc <- .self
on.exit(.currentCacheContext$cc <- oldCC)
return(func())
}
)
)
.currentCacheContext <- new.env()
# Indicates to Shiny that the given file path is part of the dependency graph
# for whatever is currently executing (so far, only ui.R). By default, ui.R only
# gets re-executed when it is detected to have changed; this function allows the
# caller to indicate that it should also re-execute if the given file changes.
#
# If NULL or NA is given as the argument, then ui.R will re-execute next time.
dependsOnFile <- function(filepath) {
if (is.null(.currentCacheContext$cc))
return()
if (is.null(filepath) || is.na(filepath))
.currentCacheContext$cc$forceDirty()
else
.currentCacheContext$cc$addDependencyFile(filepath)
}

110
R/fileupload.R Normal file
View File

@@ -0,0 +1,110 @@
# For HTML5-capable browsers, file uploads happen through a series of requests.
#
# 1. Client tells server that one or more files are about to be uploaded; the
# server responds with a "job ID" that the client should use for the rest of
# the upload.
#
# 2. For each file (sequentially):
# a. Client tells server the name, size, and type of the file.
# b. Client sends server a small-ish blob of data.
# c. Repeat 2b until the entire file has been uploaded.
# d. Client tells server that the current file is done.
#
# 3. Repeat 2 until all files have been uploaded.
#
# 4. Client tells server that all files have been uploaded, along with the
# input ID that this data should be associated with.
#
# Unfortunately this approach will not work for browsers that don't support
# HTML5 File API, but the fallback approach we would like to use (multipart
# form upload, i.e. traditional HTTP POST-based file upload) doesn't work with
# the websockets package's HTTP server at the moment.
FileUploadOperation <- setRefClass(
'FileUploadOperation',
fields = list(
.parent = 'ANY',
.id = 'character',
.files = 'data.frame',
.dir = 'character',
.currentFileInfo = 'list',
.currentFileData = 'ANY',
.pendingFileInfos = 'list'
),
methods = list(
initialize = function(parent, id, dir, fileInfos) {
.parent <<- parent
.id <<- id
.files <<- data.frame(name=character(),
size=numeric(),
type=character(),
datapath=character(),
stringsAsFactors=FALSE)
.dir <<- dir
.pendingFileInfos <<- fileInfos
},
fileBegin = function() {
if (length(.pendingFileInfos) < 1)
stop("fileBegin called too many times")
file <- .pendingFileInfos[[1]]
.currentFileInfo <<- file
.pendingFileInfos <<- tail(.pendingFileInfos, -1)
filename <- file.path(.dir, as.character(length(.files$name)))
row <- data.frame(name=file$name, size=file$size, type=file$type,
datapath=filename, stringsAsFactors=FALSE)
if (length(.files$name) == 0)
.files <<- row
else
.files <<- rbind(.files, row)
.currentFileData <<- file(filename, open='wb')
},
fileChunk = function(rawdata) {
writeBin(rawdata, .currentFileData)
},
fileEnd = function() {
close(.currentFileData)
},
finish = function() {
if (length(.pendingFileInfos) > 0)
stop("File upload job was stopped prematurely")
.parent$onJobFinished(.id)
return(.files)
}
)
)
#' @include map.R
FileUploadContext <- setRefClass(
'FileUploadContext',
fields = list(
.basedir = 'character',
.operations = 'Map'
),
methods = list(
initialize = function(dir=tempdir()) {
.basedir <<- dir
},
createUploadOperation = function(fileInfos) {
while (TRUE) {
id <- paste(as.raw(p_runif(12, min=0, max=0xFF)), collapse='')
dir <- file.path(.basedir, id)
if (!dir.create(dir))
next
op <- FileUploadOperation$new(.self, id, dir, fileInfos)
.operations$set(id, op)
return(id)
}
},
getUploadOperation = function(jobId) {
.operations$get(jobId)
},
onJobFinished = function(jobId) {
.operations$remove(jobId)
}
)
)

9
R/globals.R Normal file
View File

@@ -0,0 +1,9 @@
# A scope where we can put mutable global state
.globals <- new.env(parent = emptyenv())
.onLoad <- function(libname, pkgname) {
# R's lazy-loading package scheme causes the private seed to be cached in the
# package itself, making our PRNG completely deterministic. This line resets
# the private seed during load.
withPrivateSeed(set.seed(NULL))
}

103
R/graph.R Normal file
View File

@@ -0,0 +1,103 @@
writeReactLog <- function(file=stdout()) {
cat(RJSONIO::toJSON(.graphEnv$log, pretty=TRUE), file=file)
}
#' Reactive Log Visualizer
#'
#' Provides an interactive browser-based tool for visualizing reactive
#' dependencies and execution in your application.
#'
#' To use the reactive log visualizer, start with a fresh R session and
#' run the command \code{options(shiny.reactlog=TRUE)}; then launch your
#' application in the usual way (e.g. using \code{\link{runApp}}). At
#' any time you can hit Ctrl+F3 (or for Mac users, Command+F3) in your
#' web browser to launch the reactive log visualization.
#'
#' The reactive log visualization only includes reactive activity up
#' until the time the report was loaded. If you want to see more recent
#' activity, refresh the browser.
#'
#' Note that Shiny does not distinguish between reactive dependencies
#' that "belong" to one Shiny user session versus another, so the
#' visualization will include all reactive activity that has taken place
#' in the process, not just for a particular application or session.
#'
#' As an alternative to pressing Ctrl/Command+F3--for example, if you
#' are using reactives outside of the context of a Shiny
#' application--you can run the \code{showReactLog} function, which will
#' generate the reactive log visualization as a static HTML file and
#' launch it in your default browser. In this case, refreshing your
#' browser will not load new activity into the report; you will need to
#' call \code{showReactLog()} explicitly.
#'
#' For security and performance reasons, do not enable
#' \code{shiny.reactlog} in production environments. When the option is
#' enabled, it's possible for any user of your app to see at least some
#' of the source code of your reactive expressions and observers.
#'
#' @export
showReactLog <- function() {
browseURL(renderReactLog())
}
renderReactLog <- function() {
templateFile <- system.file('www/reactive-graph.html', package='shiny')
html <- paste(readLines(templateFile, warn=FALSE), collapse='\r\n')
tc <- textConnection(NULL, 'w')
on.exit(close(tc))
writeReactLog(tc)
cat('\n', file=tc)
flush(tc)
html <- sub('__DATA__', paste(textConnectionValue(tc), collapse='\r\n'), html, fixed=TRUE)
file <- tempfile(fileext = '.html')
writeLines(html, file)
return(file)
}
.graphAppend <- function(logEntry, domain = getDefaultReactiveDomain()) {
if (isTRUE(getOption('shiny.reactlog', FALSE)))
.graphEnv$log <- c(.graphEnv$log, list(logEntry))
if (!is.null(domain)) {
domain$reactlog(logEntry)
}
}
.graphDependsOn <- function(id, label) {
.graphAppend(list(action='dep', id=id, dependsOn=label))
}
.graphDependsOnId <- function(id, dependee) {
.graphAppend(list(action='depId', id=id, dependsOn=dependee))
}
.graphCreateContext <- function(id, label, type, prevId, domain) {
.graphAppend(list(
action='ctx', id=id, label=paste(label, collapse='\n'),
srcref=attr(label, "srcref"), srcfile=attr(label, "srcfile"),
type=type, prevId=prevId
), domain = domain)
}
.graphEnterContext <- function(id) {
.graphAppend(list(action='enter', id=id))
}
.graphExitContext <- function(id) {
.graphAppend(list(action='exit', id=id))
}
.graphValueChange <- function(label, value) {
.graphAppend(list(
action = 'valueChange',
id = label,
value = paste(capture.output(str(value)), collapse='\n')
))
}
.graphInvalidate <- function(id, domain) {
.graphAppend(list(action='invalidate', id=id), domain)
}
.graphEnv <- new.env()
.graphEnv$log <- list()

24
R/hooks.R Normal file
View File

@@ -0,0 +1,24 @@
# Call an application hook. Application hooks are provided so that front ends
# can know when a Shiny application is running:
#
# shiny.onAppStart -- called when an application begins running
# shiny.onAppStop -- called when an appliation stops
#
# Both hooks are passed the url where the application is accessible (appUrl).
# Note that the appUrl can be NULL if the application was run on a UNIX domain
# socket rather than a TCP/IP port/
callAppHook <- function(name, appUrl) {
for (hook in getHooksList(paste0("shiny.", name)))
hook(appUrl)
}
# The value for getHook can be a single function or a list of functions,
# This function ensures that the result can always be processed as a list
getHooksList <- function(name) {
hooks <- getHook(name)
if (!is.list(hooks))
hooks <- list(hooks)
hooks
}

15
R/html-deps.R Normal file
View File

@@ -0,0 +1,15 @@
createWebDependency <- function(dependency) {
if (is.null(dependency))
return(NULL)
if (!inherits(dependency, "html_dependency"))
stop("Unexpected non-html_dependency type")
if (is.null(dependency$src$href)) {
prefix <- paste(dependency$name, "-", dependency$version, sep = "")
addResourcePath(prefix, dependency$src$file)
dependency$src$href <- prefix
}
return(dependency)
}

101
R/htmltools.R Normal file
View File

@@ -0,0 +1,101 @@
#' @export
a <- htmltools::a
#' @export
br <- htmltools::br
#' @export
code <- htmltools::code
#' @export
div <- htmltools::div
#' @export
em <- htmltools::em
#' @export
h1 <- htmltools::h1
#' @export
h2 <- htmltools::h2
#' @export
h3 <- htmltools::h3
#' @export
h4 <- htmltools::h4
#' @export
h5 <- htmltools::h5
#' @export
h6 <- htmltools::h6
#' @export
hr <- htmltools::hr
#' @export
HTML <- htmltools::HTML
#' @export
img <- htmltools::img
#' @export
includeCSS <- htmltools::includeCSS
#' @export
includeHTML <- htmltools::includeHTML
#' @export
includeMarkdown <- htmltools::includeMarkdown
#' @export
includeScript <- htmltools::includeScript
#' @export
includeText <- htmltools::includeText
#' @export
is.singleton <- htmltools::is.singleton
#' @export
p <- htmltools::p
#' @export
pre <- htmltools::pre
#' @export
singleton <- htmltools::singleton
#' @export
span <- htmltools::span
#' @export
strong <- htmltools::strong
#' @export
tag <- htmltools::tag
#' @export
tagAppendAttributes <- htmltools::tagAppendAttributes
#' @export
tagAppendChild <- htmltools::tagAppendChild
#' @export
tagAppendChildren <- htmltools::tagAppendChildren
#' @export
tagList <- htmltools::tagList
#' @export
tags <- htmltools::tags
#' @export
tagSetChildren <- htmltools::tagSetChildren
#' @export
validateCssUnit <- htmltools::validateCssUnit
#' @export
withTags <- htmltools::withTags

52
R/imageutils.R Normal file
View File

@@ -0,0 +1,52 @@
#' Run a plotting function and save the output as a PNG
#'
#' This function returns the name of the PNG file that it generates. In
#' essence, it calls \code{png()}, then \code{func()}, then \code{dev.off()}.
#' So \code{func} must be a function that will generate a plot when used this
#' way.
#'
#' For output, it will try to use the following devices, in this order:
#' quartz (via \code{\link[grDevices]{png}}), then \code{\link[Cairo]{CairoPNG}},
#' and finally \code{\link[grDevices]{png}}. This is in order of quality of
#' output. Notably, plain \code{png} output on Linux and Windows may not
#' antialias some point shapes, resulting in poor quality output.
#'
#' In some cases, \code{Cairo()} provides output that looks worse than
#' \code{png()}. To disable Cairo output for an app, use
#' \code{options(shiny.usecairo=FALSE)}.
#'
#' @param func A function that generates a plot.
#' @param filename The name of the output file. Defaults to a temp file with
#' extension \code{.png}.
#' @param width Width in pixels.
#' @param height Height in pixels.
#' @param res Resolution in pixels per inch. This value is passed to
#' \code{\link{png}}. Note that this affects the resolution of PNG rendering in
#' R; it won't change the actual ppi of the browser.
#' @param ... Arguments to be passed through to \code{\link[grDevices]{png}}.
#' These can be used to set the width, height, background color, etc.
#'
#' @export
plotPNG <- function(func, filename=tempfile(fileext='.png'),
width=400, height=400, res=72, ...) {
# If quartz is available, use png() (which will default to quartz).
# Otherwise, if the Cairo package is installed, use CairoPNG().
# Finally, if neither quartz nor Cairo, use png().
if (capabilities("aqua")) {
pngfun <- png
} else if (getOption('shiny.usecairo', TRUE) &&
nchar(system.file(package = "Cairo"))) {
pngfun <- Cairo::CairoPNG
} else {
pngfun <- png
}
pngfun(filename=filename, width=width, height=height, res=res, ...)
# Call plot.new() so that even if no plotting operations are performed
# at least we have a blank background
plot.new()
dv <- dev.cur()
tryCatch(shinyCallingHandlers(func()), finally = dev.off(dv))
filename
}

104
R/jqueryui.R Normal file
View File

@@ -0,0 +1,104 @@
#' Panel with absolute positioning
#'
#' Creates a panel whose contents are absolutely positioned.
#'
#' The \code{absolutePanel} function creates a \code{<div>} tag whose CSS
#' position is set to \code{absolute} (or fixed if \code{fixed = TRUE}). The way
#' absolute positioning works in HTML is that absolute coordinates are specified
#' relative to its nearest parent element whose position is not set to
#' \code{static} (which is the default), and if no such parent is found, then
#' relative to the page borders. If you're not sure what that means, just keep
#' in mind that you may get strange results if you use \code{absolutePanel} from
#' inside of certain types of panels.
#'
#' The \code{fixedPanel} function is the same as \code{absolutePanel} with
#' \code{fixed = TRUE}.
#'
#' The position (\code{top}, \code{left}, \code{right}, \code{bottom}) and size
#' (\code{width}, \code{height}) parameters are all optional, but you should
#' specify exactly two of \code{top}, \code{bottom}, and \code{height} and
#' exactly two of \code{left}, \code{right}, and \code{width} for predictable
#' results.
#'
#' Like most other distance parameters in Shiny, the position and size
#' parameters take a number (interpreted as pixels) or a valid CSS size string,
#' such as \code{"100px"} (100 pixels) or \code{"25\%"}.
#'
#' For arcane HTML reasons, to have the panel fill the page or parent you should
#' specify \code{0} for \code{top}, \code{left}, \code{right}, and \code{bottom}
#' rather than the more obvious \code{width = "100\%"} and \code{height =
#' "100\%"}.
#'
#' @param ... Attributes (named arguments) or children (unnamed arguments) that
#' should be included in the panel.
#'
#' @param top Distance between the top of the panel, and the top of the page or
#' parent container.
#' @param left Distance between the left side of the panel, and the left of the
#' page or parent container.
#' @param right Distance between the right side of the panel, and the right of
#' the page or parent container.
#' @param bottom Distance between the bottom of the panel, and the bottom of the
#' page or parent container.
#' @param width Width of the panel.
#' @param height Height of the panel.
#' @param draggable If \code{TRUE}, allows the user to move the panel by
#' clicking and dragging.
#' @param fixed Positions the panel relative to the browser window and prevents
#' it from being scrolled with the rest of the page.
#' @param cursor The type of cursor that should appear when the user mouses over
#' the panel. Use \code{"move"} for a north-east-south-west icon,
#' \code{"default"} for the usual cursor arrow, or \code{"inherit"} for the
#' usual cursor behavior (including changing to an I-beam when the cursor is
#' over text). The default is \code{"auto"}, which is equivalent to
#' \code{ifelse(draggable, "move", "inherit")}.
#' @return An HTML element or list of elements.
#'
#' @export
absolutePanel <- function(...,
top = NULL, left = NULL, right = NULL, bottom = NULL,
width = NULL, height = NULL,
draggable = FALSE, fixed = FALSE,
cursor = c('auto', 'move', 'default', 'inherit')) {
cssProps <- list(
top = top,
left = left,
right = right,
bottom = bottom,
width = width,
height = height
)
cssProps <- cssProps[!sapply(cssProps, is.null)]
cssProps <- sapply(cssProps, validateCssUnit)
cssProps[['position']] <- ifelse(fixed, 'fixed', 'absolute')
cssProps[['cursor']] <- match.arg(cursor)
if (identical(cssProps[['cursor']], 'auto'))
cssProps[['cursor']] <- ifelse(draggable, 'move', 'inherit')
style <- paste(paste(names(cssProps), cssProps, sep = ':', collapse = ';'), ';', sep='')
divTag <- tags$div(style=style, ...)
if (isTRUE(draggable)) {
divTag <- tagAppendAttributes(divTag, class='draggable')
return(tagList(
# IMPORTANT NOTE: If you update jqueryui, make sure you DON'T include the datepicker,
# as it collides with our bootstrap datepicker!
singleton(tags$head(tags$script(src='shared/jqueryui/1.10.4/jquery-ui.min.js'))),
divTag,
tags$script('$(".draggable").draggable();')
))
} else {
return(divTag)
}
}
#' @rdname absolutePanel
#' @export
fixedPanel <- function(...,
top = NULL, left = NULL, right = NULL, bottom = NULL,
width = NULL, height = NULL,
draggable = FALSE,
cursor = c('move', 'default', 'inherit')) {
absolutePanel(..., top=top, left=left, right=right, bottom=bottom,
width=width, height=height, draggable=draggable, cursor=cursor,
fixed=TRUE)
}

67
R/map.R Normal file
View File

@@ -0,0 +1,67 @@
# TESTS
# Simple set/get
# Simple remove
# Simple containsKey
# Simple keys
# Simple values
# Simple clear
# Get of unknown key returns NULL
# Remove of unknown key does nothing
# Setting a key twice always results in last-one-wins
# /TESTS
Map <- setRefClass(
'Map',
fields = list(
.env = 'environment'
),
methods = list(
initialize = function() {
.env <<- new.env(parent=emptyenv())
},
get = function(key) {
if (.self$containsKey(key))
base::get(key, pos=.env, inherits=FALSE)
},
set = function(key, value) {
assign(key, value, pos=.env, inherits=FALSE)
value
},
mset = function(...) {
args <- list(...)
for (key in names(args))
set(key, args[[key]])
},
remove = function(key) {
if (.self$containsKey(key)) {
result <- .self$get(key)
rm(list = key, pos=.env, inherits=FALSE)
result
}
},
containsKey = function(key) {
exists(key, where=.env, inherits=FALSE)
},
keys = function() {
ls(envir=.env, all.names=TRUE)
},
values = function() {
mget(.self$keys(), envir=.env, inherits=FALSE)
},
clear = function() {
.env <<- new.env(parent=emptyenv())
invisible(NULL)
},
size = function() {
length(.env)
}
)
)
as.list.Map <- function(map) {
sapply(map$keys(),
map$get,
simplify=FALSE)
}
length.Map <- function(map) {
map$size()
}

71
R/middleware-shiny.R Normal file
View File

@@ -0,0 +1,71 @@
#' @include globals.R
NULL
reactLogHandler <- function(req) {
if (!identical(req$PATH_INFO, '/reactlog'))
return(NULL)
if (!getOption('shiny.reactlog', FALSE)) {
return(NULL)
}
return(httpResponse(
status=200,
content=list(file=renderReactLog(), owned=TRUE)
))
}
sessionHandler <- function(req) {
path <- req$PATH_INFO
if (is.null(path))
return(NULL)
matches <- regmatches(path, regexec('^(/session/([0-9a-f]+))(/.*)$', path))
if (length(matches[[1]]) == 0)
return(NULL)
session <- matches[[1]][3]
subpath <- matches[[1]][4]
shinysession <- appsByToken$get(session)
if (is.null(shinysession))
return(NULL)
subreq <- as.environment(as.list(req, all.names=TRUE))
subreq$PATH_INFO <- subpath
subreq$SCRIPT_NAME <- paste(subreq$SCRIPT_NAME, matches[[1]][2], sep='')
return(shinysession$handleRequest(subreq))
}
dynamicHandler <- function(filePath, dependencyFiles=filePath) {
lastKnownTimestamps <- NA
metaHandler <- function(req) NULL
if (!file.exists(filePath))
return(metaHandler)
cacheContext <- CacheContext$new()
return (function(req) {
# Check if we need to rebuild
if (cacheContext$isDirty()) {
cacheContext$reset()
for (dep in dependencyFiles)
cacheContext$addDependencyFile(dep)
clearClients()
if (file.exists(filePath)) {
local({
cacheContext$with(function() {
sys.source(filePath, envir=new.env(parent=globalenv()), keep.source=TRUE)
})
})
}
metaHandler <<- joinHandlers(.globals$clients)
clearClients()
}
return(metaHandler(req))
})
}

354
R/middleware.R Normal file
View File

@@ -0,0 +1,354 @@
# This file contains a general toolkit for routing and combining bits of
# HTTP-handling logic. It is similar in spirit to Rook (and Rack, and WSGI, and
# Connect, and...) but adds cascading and routing.
#
# This file is called "middleware" because that's the term used for these bits
# of logic in these other frameworks. However, our code uses the word "handler"
# so we'll stick to that for the rest of this document; just know that they're
# basically the same concept.
#
# ## Intro to handlers
#
# A **handler** (or sometimes, **httpHandler**) is a function that takes a
# `req` parameter--a request object as described in the Rook specification--and
# returns `NULL`, or an `httpResponse`.
#
## ------------------------------------------------------------------------
httpResponse <- function(status = 200,
content_type = "text/html; charset=UTF-8",
content = "",
headers = list()) {
# Make sure it's a list, not a vector
headers <- as.list(headers)
if (is.null(headers$`X-UA-Compatible`))
headers$`X-UA-Compatible` <- "chrome=1"
resp <- list(status = status, content_type = content_type, content = content,
headers = headers)
class(resp) <- 'httpResponse'
return(resp)
}
#
# You can think of a web application as being simply an aggregation of these
# functions, each of which performs one kind of duty. Each handler in turn gets
# a look at the request and can decide whether it knows how to handle it. If
# so, it returns an `httpResponse` and processing terminates; if not, it
# returns `NULL` and the next handler gets to execute. If the final handler
# returns `NULL`, a 404 response should be returned.
#
# We have a similar construct for websockets: **websocket handlers** or
# **wsHandlers**. These take a single `ws` argument which is the websocket
# connection that was just opened, and they can either return `TRUE` if they
# are handling the connection, and `NULL` to pass responsibility on to the next
# wsHandler.
#
# ### Combining handlers
#
# Since it's so common for httpHandlers to be invoked in this "cascading"
# fashion, we'll introduce a function that takes zero or more handlers and
# returns a single handler. And while we're at it, making a directory of static
# content available is such a common thing to do, we'll allow strings
# representing paths to be used instead of handlers; any such strings we
# encounter will be converted into `staticHandler` objects.
#
## ------------------------------------------------------------------------
joinHandlers <- function(handlers) {
# Zero handlers; return a null handler
if (length(handlers) == 0)
return(function(req) NULL)
# Just one handler (function)? Return it.
if (is.function(handlers))
return(handlers)
handlers <- lapply(handlers, function(h) {
if (is.character(h))
return(staticHandler(h))
else
return(h)
})
# Filter out NULL
handlers <- handlers[!sapply(handlers, is.null)]
if (length(handlers) == 0)
return(function(req) NULL)
if (length(handlers) == 1)
return(handlers[[1]])
function(req) {
for (handler in handlers) {
response <- handler(req)
if (!is.null(response))
return(response)
}
return(NULL)
}
}
#
# Note that we don't have an equivalent of `joinHandlers` for wsHandlers. It's
# easy to imagine it, we just haven't needed one.
#
# ### Handler routing
#
# Handlers do not have a built-in notion of routing. Conceptually, given a list
# of handlers, all the handlers are peers and they all get to see every request
# (well, up until the point that a handler returns a response).
#
# You could implement routing in each handler by checking the request's
# `PATH_INFO` field, but since it's such a common need, let's make it simple by
# introducing a `routeHandler` function. This is a handler
# [decorator](http://en.wikipedia.org/wiki/Decorator_pattern) and it's
# responsible for 1) filtering out requests that don't match the given route,
# and 2) temporarily modifying the request object to take the matched part of
# the route off of the `PATH_INFO` (and add it to the end of `SCRIPT_NAME`).
# This way, the handler doesn't need to figure out about what part of its URL
# path has already been matched via routing.
#
# (BTW, it's safe for `routeHandler` calls to nest.)
#
## ------------------------------------------------------------------------
routeHandler <- function(prefix, handler) {
force(prefix)
force(handler)
if (identical("", prefix))
return(handler)
if (length(prefix) != 1 || !isTRUE(grepl("^/[^\\]+$", prefix))) {
stop("Invalid URL prefix \"", prefix, "\"")
}
pathPattern <- paste("^\\Q", prefix, "\\E/", sep = "")
function(req) {
if (isTRUE(grepl(pathPattern, req$PATH_INFO))) {
origScript <- req$SCRIPT_NAME
origPath <- req$PATH_INFO
on.exit({
req$SCRIPT_NAME <- origScript
req$PATH_INFO <- origPath
}, add = TRUE)
pathInfo <- substr(req$PATH_INFO, nchar(prefix)+1, nchar(req$PATH_INFO))
req$SCRIPT_NAME <- paste(req$SCRIPT_NAME, prefix, sep = "")
req$PATH_INFO <- pathInfo
return(handler(req))
} else {
return(NULL)
}
}
}
#
# We have a version for websocket handlers as well. Pity about the copy/paste
# job.
#
## ------------------------------------------------------------------------
routeWSHandler <- function(prefix, wshandler) {
force(prefix)
force(wshandler)
if (identical("", prefix))
return(wshandler)
if (length(prefix) != 1 || !isTRUE(grepl("^/[^\\]+$", prefix))) {
stop("Invalid URL prefix \"", prefix, "\"")
}
pathPattern <- paste("^\\Q", prefix, "\\E/", sep = "")
function(ws) {
req <- ws$request
if (isTRUE(grepl(pathPattern, req$PATH_INFO))) {
origScript <- req$SCRIPT_NAME
origPath <- req$PATH_INFO
on.exit({
req$SCRIPT_NAME <- origScript
req$PATH_INFO <- origPath
}, add = TRUE)
pathInfo <- substr(req$PATH_INFO, nchar(prefix)+1, nchar(req$PATH_INFO))
req$SCRIPT_NAME <- paste(req$SCRIPT_NAME, prefix, sep = "")
req$PATH_INFO <- pathInfo
return(wshandler(ws))
} else {
return(NULL)
}
}
}
#
# ### Handler implementations
#
# Now let's actually write some handlers. Note that these functions aren't
# *themselves* handlers, you call them and they *return* a handler. Handler
# factory functions, if you will.
#
# Here's one that serves up static assets from a directory.
#
## ------------------------------------------------------------------------
staticHandler <- function(root) {
force(root)
return(function(req) {
if (!identical(req$REQUEST_METHOD, 'GET'))
return(NULL)
path <- req$PATH_INFO
if (is.null(path))
return(httpResponse(400, content="<h1>Bad Request</h1>"))
if (path == '/')
path <- '/index.html'
abs.path <- resolve(root, path)
if (is.null(abs.path))
return(NULL)
ext <- tools::file_ext(abs.path)
content.type <- getContentType(ext)
response.content <- readBin(abs.path, 'raw', n=file.info(abs.path)$size)
return(httpResponse(200, content.type, response.content))
})
}
#
# ## Handler manager
#
# The handler manager gives you a place to register handlers (of both http and
# websocket varieties) and provides an httpuv-compatible set of callbacks for
# invoking them.
#
# Create one of these, make zero or more calls to `addHandler` and
# `addWSHandler` methods (order matters--first one wins!), and then pass the
# return value of `createHttpuvApp` to httpuv's `startServer` function.
#
## ------------------------------------------------------------------------
HandlerList <- setRefClass("HandlerList",
fields = list(
handlers = "list"
),
methods = list(
add = function(handler, key, tail = FALSE) {
if (!is.null(handlers[[key]]))
stop("Key ", key, " already in use")
newList <- structure(names=key, list(handler))
if (length(handlers) == 0)
handlers <<- newList
else if (tail)
handlers <<- c(handlers, newList)
else
handlers <<- c(newList, handlers)
},
remove = function(key) {
handlers[key] <<- NULL
},
clear = function() {
handlers <<- list()
},
invoke = function(...) {
for (handler in handlers) {
result <- handler(...)
if (!is.null(result))
return(result)
}
return(NULL)
}
)
)
HandlerManager <- setRefClass("HandlerManager",
fields = list(
handlers = "HandlerList",
wsHandlers = "HandlerList"
),
methods = list(
addHandler = function(handler, key, tail = FALSE) {
handlers$add(handler, key, tail)
},
removeHandler = function(key) {
handlers$remove(key)
},
addWSHandler = function(wsHandler, key, tail = FALSE) {
wsHandlers$add(wsHandler, key, tail)
},
removeWSHandler = function(key) {
wsHandlers$remove(key)
},
clear = function() {
handlers$clear()
wsHandlers$clear()
},
createHttpuvApp = function() {
list(
onHeaders = function(req) {
maxSize <- getOption('shiny.maxRequestSize', 5 * 1024 * 1024)
if (maxSize <= 0)
return(NULL)
reqSize <- 0
if (length(req$CONTENT_LENGTH) > 0)
reqSize <- as.numeric(req$CONTENT_LENGTH)
else if (length(req$HTTP_TRANSFER_ENCODING) > 0)
reqSize <- Inf
if (reqSize > maxSize) {
return(list(status = 413L,
headers = list(
'Content-Type' = 'text/plain'
),
body = 'Maximum upload size exceeded'))
}
else {
return(NULL)
}
},
call = .httpServer(
function (req) {
return(handlers$invoke(req))
},
getOption('shiny.sharedSecret', NULL)
),
onWSOpen = function(ws) {
return(wsHandlers$invoke(ws))
}
)
},
.httpServer = function(handler, sharedSecret) {
filter <- getOption('shiny.http.response.filter', NULL)
if (is.null(filter))
filter <- function(req, response) response
function(req) {
if (!is.null(sharedSecret)
&& !identical(sharedSecret, req$HTTP_SHINY_SHARED_SECRET)) {
return(list(status=403,
body='<h1>403 Forbidden</h1><p>Shared secret mismatch</p>',
headers=list('Content-Type' = 'text/html')))
}
response <- handler(req)
if (is.null(response))
response <- httpResponse(404, content="<h1>Not Found</h1>")
if (inherits(response, "httpResponse")) {
headers <- as.list(response$headers)
headers$'Content-Type' <- response$content_type
response <- filter(req, response)
return(list(status=response$status,
body=response$content,
headers=headers))
} else {
# Assume it's a Rook-compatible response
return(response)
}
}
}
)
)
#
# ## Next steps
#
# See server.R and middleware-shiny.R to see actual implementation and usage of
# handlers in the context of Shiny.

110
R/priorityqueue.R Normal file
View File

@@ -0,0 +1,110 @@
# "...like a regular queue or stack data structure, but where additionally each
# element has a "priority" associated with it. In a priority queue, an element
# with high priority is served before an element with low priority. If two
# elements have the same priority, they are served according to their order in
# the queue." (http://en.wikipedia.org/wiki/Priority_queue)
PriorityQueue <- setRefClass(
'PriorityQueue',
fields = list(
# Keys are priorities, values are subqueues (implemented as list)
.itemsByPriority = 'Map',
# Sorted vector (largest first)
.priorities = 'numeric'
),
methods = list(
# Enqueue an item, with the given priority level (must be integer). Higher
# priority numbers are dequeued earlier than lower.
enqueue = function(item, priority) {
priority <- normalizePriority(priority)
if (!(priority %in% .priorities)) {
.priorities <<- c(.priorities, priority)
.priorities <<- sort(.priorities, decreasing=TRUE)
.itemsByPriority$set(.key(priority), list(item))
} else {
.itemsByPriority$set(
.key(priority),
c(.itemsByPriority$get(.key(priority)), item)
)
}
return(invisible())
},
# Retrieve a single item by 1) priority number (highest first) and then 2)
# insertion order (first in, first out). If there are no items to be
# dequeued, then NULL is returned. If it is necessary to distinguish between
# a NULL value and the empty case, call isEmpty() before dequeue().
dequeue = function() {
if (length(.priorities) == 0)
return(NULL)
maxPriority <- .priorities[[1]]
items <- .itemsByPriority$get(.key(maxPriority))
firstItem <- items[[1]]
if (length(items) == 1) {
# This is the last item at this priority. Remove both the list and the
# priority level.
.itemsByPriority$remove(.key(maxPriority))
.priorities <<- .priorities[-1]
} else {
# There are still items at this priority. Remove the current item from
# the list, and save it.
items <- items[-1]
.itemsByPriority$set(.key(maxPriority), items)
}
return(firstItem)
},
# Returns TRUE if no items are in the queue, otherwise FALSE.
isEmpty = function() {
length(.priorities) == 0
},
# Translates a priority integer to a character that is suitable for using as
# a key.
.key = function(priority) {
sprintf('%a', priority)
}
)
)
normalizePriority <- function(priority) {
if (is.null(priority))
priority <- 0
# Cast integers to numeric to prevent any inconsistencies
if (is.integer(priority))
priority <- as.numeric(priority)
if (!is.numeric(priority))
stop('priority must be an integer or numeric')
# Check length
if (length(priority) == 0) {
warning('Zero-length priority vector was passed; using 0')
priority <- 0
} else if (length(priority) > 1) {
warning('Priority has length > 1 and only the first element will be used')
priority <- priority[1]
}
# NA == 0
if (is.na(priority))
priority <- 0
return(priority)
}
# pq <- PriorityQueue$new()
# pq$enqueue('a', 1)
# pq$enqueue('b', 1L)
# pq$enqueue('c', 1)
# pq$enqueue('A', 2)
# pq$enqueue('B', 2L)
# pq$enqueue('C', 2)
# pq$enqueue('d', 1)
# pq$enqueue('e', 1L)
# pq$enqueue('f', 1)
# pq$enqueue('D', 2)
# pq$enqueue('E', 2L)
# pq$enqueue('F', 2)
# # Expect ABCDEFabcdef

377
R/react.R
View File

@@ -1,106 +1,77 @@
# TESTS
# Simple set/get
# Simple remove
# Simple contains.key
# Simple keys
# Simple values
# Simple clear
# Get of unknown key returns NULL
# Remove of unknown key does nothing
# Setting a key twice always results in last-one-wins
# /TESTS
Map <- setRefClass(
'Map',
fields = list(
.env = 'environment'
),
methods = list(
initialize = function() {
.env <<- new.env(parent=emptyenv())
},
get = function(key) {
if (.self$contains.key(key))
return(base::get(key, pos=.env, inherits=F))
else
return(NULL)
},
set = function(key, value) {
assign(key, value, pos=.env, inherits=F)
return(value)
},
remove = function(key) {
if (.self$contains.key(key)) {
result <- .self$get(key)
rm(list = key, pos=.env, inherits=F)
return(result)
}
return(NULL)
},
contains.key = function(key) {
exists(key, where=.env, inherits=F)
},
keys = function() {
ls(envir=.env, all.names=T)
},
values = function() {
mget(.self$keys(), envir=.env, inherits=F)
},
clear = function() {
.env <<- new.env(parent=emptyenv())
invisible(NULL)
},
size = function() {
length(.env)
}
)
)
as.list.Map <- function(map) {
sapply(map$keys(),
map$get,
simplify=F)
}
length.Map <- function(map) {
map$size()
}
Context <- setRefClass(
'Context',
fields = list(
id = 'character',
.label = 'character', # For debug purposes
.invalidated = 'logical',
.callbacks = 'list'
.invalidateCallbacks = 'list',
.flushCallbacks = 'list',
.domain = 'ANY'
),
methods = list(
initialize = function() {
id <<- .get.reactive.environment()$next.id()
.invalidated <<- F
.callbacks <<- list()
initialize = function(domain, label='', type='other', prevId='') {
id <<- .getReactiveEnvironment()$nextId()
.invalidated <<- FALSE
.invalidateCallbacks <<- list()
.flushCallbacks <<- list()
.label <<- label
.domain <<- domain
.graphCreateContext(id, label, type, prevId, domain)
},
run = function(func) {
env <- .get.reactive.environment()
old.ctx <- env$current.context(warn=F)
env$set.current.context(.self)
on.exit(env$set.current.context(old.ctx))
func()
"Run the provided function under this context."
withReactiveDomain(.domain, {
env <- .getReactiveEnvironment()
.graphEnterContext(id)
tryCatch(
env$runWith(.self, func),
finally = .graphExitContext(id)
)
})
},
invalidate = function() {
"Invalidate this context. It will immediately call the callbacks
that have been registered with onInvalidate()."
if (.invalidated)
return()
.invalidated <<- T
.get.reactive.environment()$add.pending.invalidate(.self)
.invalidated <<- TRUE
.graphInvalidate(id, .domain)
lapply(.invalidateCallbacks, function(func) {
func()
})
.invalidateCallbacks <<- list()
NULL
},
on.invalidate = function(func) {
onInvalidate = function(func) {
"Register a function to be called when this context is invalidated.
If this context is already invalidated, the function is called
immediately."
if (.invalidated)
func()
else
.callbacks <<- c(.callbacks, func)
.invalidateCallbacks <<- c(.invalidateCallbacks, func)
NULL
},
execute.callbacks = function() {
lapply(.callbacks, function(func) {
func()
addPendingFlush = function(priority) {
"Tell the reactive environment that this context should be flushed the
next time flushReact() called."
.getReactiveEnvironment()$addPendingFlush(.self, priority)
},
onFlush = function(func) {
"Register a function to be called when this context is flushed."
.flushCallbacks <<- c(.flushCallbacks, func)
},
executeFlushCallbacks = function() {
"For internal use only."
lapply(.flushCallbacks, function(func) {
withCallingHandlers({
func()
}, warning = function(e) {
# TODO: Callbacks in app
}, error = function(e) {
# TODO: Callbacks in app
})
})
}
)
@@ -108,196 +79,86 @@ Context <- setRefClass(
ReactiveEnvironment <- setRefClass(
'ReactiveEnvironment',
fields = c('.current.context', '.next.id', '.pending.invalidate'),
fields = list(
.currentContext = 'ANY',
.nextId = 'integer',
.pendingFlush = 'PriorityQueue',
.inFlush = 'logical'
),
methods = list(
initialize = function() {
.current.context <<- NULL
.next.id <<- 0L
.pending.invalidate <<- list()
.currentContext <<- NULL
.nextId <<- 0L
.pendingFlush <<- PriorityQueue$new()
.inFlush <<- FALSE
},
next.id = function() {
.next.id <<- .next.id + 1L
return(as.character(.next.id))
nextId = function() {
.nextId <<- .nextId + 1L
return(as.character(.nextId))
},
current.context = function(warn=T) {
if (warn && is.null(.current.context))
warning('No reactive context is active')
return(.current.context)
currentContext = function() {
if (is.null(.currentContext)) {
if (isTRUE(getOption('shiny.suppressMissingContextError', FALSE))) {
return(getDummyContext())
} else {
stop('Operation not allowed without an active reactive context. ',
'(You tried to do something that can only be done from inside a ',
'reactive expression or observer.)')
}
}
return(.currentContext)
},
set.current.context = function(ctx) {
.current.context <<- ctx
runWith = function(ctx, func) {
old.ctx <- .currentContext
.currentContext <<- ctx
on.exit(.currentContext <<- old.ctx)
shinyCallingHandlers(func())
},
add.pending.invalidate = function(ctx) {
.pending.invalidate <<- c(.pending.invalidate, ctx)
addPendingFlush = function(ctx, priority) {
.pendingFlush$enqueue(ctx, priority)
},
flush = function() {
while (length(.pending.invalidate) > 0) {
contexts <- .pending.invalidate
.pending.invalidate <<- list()
lapply(contexts, function(ctx) {
ctx$execute.callbacks()
NULL
})
# If already in a flush, don't start another one
if (.inFlush) return()
.inFlush <<- TRUE
on.exit(.inFlush <<- FALSE)
while (!.pendingFlush$isEmpty()) {
ctx <- .pendingFlush$dequeue()
ctx$executeFlushCallbacks()
}
}
)
)
Values <- setRefClass(
'Values',
fields = list(
.values = 'environment',
.dependencies = 'environment'
),
methods = list(
initialize = function() {
.values <<- new.env(parent=emptyenv())
.dependencies <<- new.env(parent=emptyenv())
},
get = function(key) {
ctx <- .get.reactive.environment()$current.context()
dep.key <- paste(key, ':', ctx$id, sep='')
if (!exists(dep.key, where=.dependencies, inherits=F)) {
assign(dep.key, ctx, pos=.dependencies, inherits=F)
ctx$on.invalidate(function() {
rm(list=dep.key, pos=.dependencies, inherits=F)
})
}
if (!exists(key, where=.values, inherits=F))
NULL
else
base::get(key, pos=.values, inherits=F)
},
set = function(key, value) {
if (exists(key, where=.values, inherits=F)) {
if (identical(base::get(key, pos=.values, inherits=F), value)) {
return(invisible())
}
}
assign(key, value, pos=.values, inherits=F)
dep.keys <- objects(
pos=.dependencies,
pattern=paste('^\\Q', key, ':', '\\E', '\\d+$', sep='')
)
lapply(
mget(dep.keys, envir=.dependencies),
function(ctx) {
ctx$invalidate()
NULL
}
)
invisible()
},
mset = function(lst) {
lapply(names(lst),
function(name) {
.self$set(name, lst[[name]])
})
}
)
)
Observable <- setRefClass(
'Observable',
fields = c(
'.func', # function
'.dependencies', # Map
'.initialized', # logical
'.value' # any
),
methods = list(
initialize = function(func) {
.func <<- func
.dependencies <<- Map$new()
.initialized <<- F
},
get.value = function() {
if (!.initialized) {
.initialized <<- T
.self$.update.value()
}
ctx <- .get.reactive.environment()$current.context()
if (!.dependencies$contains.key(ctx$id)) {
.dependencies$set(ctx$id, ctx)
ctx$on.invalidate(function() {
.dependencies$remove(ctx$id)
})
}
return(.value)
},
.update.value = function() {
old.value <- .value
ctx <- Context$new()
ctx$on.invalidate(function() {
.self$.update.value()
})
ctx$run(function() {
.value <<- .func()
})
if (!identical(old.value, .value)) {
lapply(
.dependencies$values(),
function(dep.ctx) {
dep.ctx$invalidate()
NULL
}
)
}
}
)
)
Observer <- setRefClass(
'Observer',
fields = list(
.func = 'function'
),
methods = list(
initialize = function(func) {
.func <<- func
.self$run()
},
run = function() {
ctx <- Context$new()
ctx$on.invalidate(function() {
run()
})
ctx$run(.func)
}
)
)
.get.reactive.environment <- function() {
if (!exists('.ReactiveEnvironment', envir=.GlobalEnv, inherits=F)) {
assign('.ReactiveEnvironment', ReactiveEnvironment$new(), envir=.GlobalEnv)
.getReactiveEnvironment <- local({
reactiveEnvironment <- NULL
function() {
if (is.null(reactiveEnvironment))
reactiveEnvironment <<- ReactiveEnvironment$new()
return(reactiveEnvironment)
}
get('.ReactiveEnvironment', envir=.GlobalEnv, inherits=F)
})
# Causes any pending invalidations to run.
flushReact <- function() {
.getReactiveEnvironment()$flush()
}
flush.react <- function() {
.get.reactive.environment()$flush()
# Retrieves the current reactive context, or errors if there is no reactive
# context active at the moment.
getCurrentContext <- function() {
.getReactiveEnvironment()$currentContext()
}
test <- function () {
values <- Values$new()
obs <- Observer$new(function() {print(values$get('foo'))})
flush.react()
values$set('foo', 'bar')
flush.react()
values$set('a', 100)
values$set('b', 250)
observable <- Observable$new(function() {
values$get('a') + values$get('b')
})
obs2 <- Observer$new(function() {print(paste0('a+b: ', observable$get.value()))})
flush.react()
values$set('b', 300)
flush.react()
values$mset(list(a = 10, b = 20))
flush.react()
}
getDummyContext <- function() {}
local({
dummyContext <- NULL
getDummyContext <<- function() {
if (is.null(dummyContext)) {
dummyContext <<- Context$new(getDefaultReactiveDomain(), '[none]',
type='isolate')
}
return(dummyContext)
}
})

252
R/reactive-domains.R Normal file
View File

@@ -0,0 +1,252 @@
#' @include globals.R
NULL
#
# Over the last few months we've seen a number of cases where it'd be helpful
# for objects that are instantiated within a Shiny app to know what Shiny
# session they are "owned" by. I put "owned" in quotes because there isn't a
# built-in notion of object ownership in Shiny today, any more than there is a
# notion of one object owning another in R.
#
# But it's intuitive to everyone, I think, that the outputs for a session are
# owned by that session, and any logic that is executed as part of the output
# is done on behalf of that session. And it seems like in the vast majority of
# cases, observers that are created inside a shinyServer function (i.e. one per
# session) are also intuitively owned by the session that's starting up.
#
# This notion of ownership is important/helpful for a few scenarios that have
# come up in recent months:
#
# 1. The showcase mode that Jonathan implemented recently highlights
# observers/reactives as they execute. In order for sessions to only receive
# highlights for their own code execution, we need to know which sessions own
# which observers. 2. We've seen a number of apps crash out when observers
# outlive their sessions and then try to do things with their sessions (the
# most common error message was something like "Can't write to a closed
# websocket", but we now silently ignore writes to closed websockets). It'd be
# convenient for the default behavior of observers to be that they don't
# outlive their parent sessions. 3. The reactive log visualizer currently
# visualizes all reactivity in the process; it would be great if by default it
# only visualized the current session. 4. When an observer has an error, it
# would be great to be able to send the error to the session so it can do its
# own handling (such as sending the error info to the client so the user can be
# notified). 5. Shiny Server Pro wants to show the admin how much time is being
# spent servicing each session.
#
# So what are the rules for establishing ownership?
#
# 1. Define the "current domain" as a global variable whose value will own any
# newly created observer (by default). A domain is a reference class or
# environment that contains the functions `onEnded(callback)`, `isEnded()`, and
# `reactlog(logEntry)`.
#
## ------------------------------------------------------------------------
createMockDomain <- function() {
callbacks <- list()
ended <- FALSE
domain <- new.env(parent = emptyenv())
domain$onEnded <- function(callback) {
callbacks <<- c(callbacks, callback)
}
domain$isEnded <- function() {
ended
}
domain$reactlog <- function(logEntry) NULL
domain$end <- function() {
if (!ended) {
ended <<- TRUE
lapply(callbacks, do.call, list())
}
invisible()
}
return(domain)
}
#
# 2. The initial value of "current domain" is null.
#
## ------------------------------------------------------------------------
.globals$domain <- NULL
#
# 3. Objects that can be owned include observers, reactive expressions,
# invalidateLater instances, reactiveTimer instances. Whenever one of these is
# created, by default its owner will be the current domain.
#
## ------------------------------------------------------------------------
#' @rdname domains
#' @export
getDefaultReactiveDomain <- function() {
.globals$domain
}
#
# 4. While a session is being created and the shinyServer function is executed,
# the current domain is set to the new session. When the shinyServer function
# is done executing, the previous value of the current domain is restored. This
# is made foolproof using a `withReactiveDomain` function.
#
## ------------------------------------------------------------------------
#' @rdname domains
#' @export
withReactiveDomain <- function(domain, expr) {
oldValue <- .globals$domain
.globals$domain <- domain
on.exit(.globals$domain <- oldValue)
expr
}
#
# 5. While an observer or reactive expression is executing, the current domain
# is set to the owner of the observer. When the observer completes, the
# previous value of the current domain is restored.
#
# 6. Note that once created, an observer/reactive expression belongs to the
# same domain forever, regardless of how many times it is invalidated and
# re-executed, and regardless of what caused the invalidation to happen.
#
# 7. When a session ends, any observers that it owns are suspended, any
# invalidateLater/reactiveTimers are stopped.
#
## ------------------------------------------------------------------------
#' @rdname domains
#' @export
onReactiveDomainEnded <- function(domain, callback, failIfNull = FALSE) {
if (is.null(domain)) {
if (isTRUE(failIfNull))
stop("onReactiveDomainEnded called with null domain and failIfNull=TRUE")
else
return()
}
domain$onEnded(callback)
}
#
# 8. If an uncaught error occurs while executing an observer, the session gets
# a chance to handle it. I suppose the default behavior would be to send the
# message to the client if possible, and then perhaps end the session (or not,
# I could argue either way).
#
# The basic idea here is inspired by Node.js domains, which you can think of as
# a way to track execution contexts across callback- or listener-oriented
# asynchronous code. They use it to unify error handling code across a graph of
# related objects. Our domains will be to unify both lifetime and error
# handling across a graph of related reactive primitives.
#
# (You could imagine that as a client update is being processed, the session
# associated with that client would become the current domain. IIRC this is how
# showcase mode is implemented today. I don't think this would cover any cases
# not covered by rule 5 above, and the absence of rule 5 would leave cases that
# this rule would not cover.)
#
# Pitfalls/open issues:
#
# 1. Our current approach has the issue of observers staying alive longer than
# they ought to. This proposal introduces the opposite risk: that
# observers/invalidateLater/reactiveTimer instances, having implicitly been
# assigned a parent, are suspended/disposed earlier than they ought to have
# been. I find this especially worrisome for invalidateLater/reactiveTimer,
# which will often be called in a reactive expression, and thus execute under
# unpredictable circumstances. Perhaps those should continue to accept an
# explicit "session=" parameter that the user is warned about if they don't
# provide a value.
#
# 2. Are there situations where it is ambiguous what the right thing to do is,
# and we should warn/error to ask the user to provide a domain explicitly?
#
## ------------------------------------------------------------------------
#' Reactive domains
#'
#' Reactive domains are a mechanism for establishing ownership over reactive
#' primitives (like reactive expressions and observers), even if the set of
#' reactive primitives is dynamically created. This is useful for lifetime
#' management (i.e. destroying observers when the Shiny session that created
#' them ends) and error handling.
#'
#' At any given time, there can be either a single "default" reactive domain
#' object, or none (i.e. the reactive domain object is \code{NULL}). You can
#' access the current default reactive domain by calling
#' \code{getDefaultReactiveDomain}.
#'
#' Unless you specify otherwise, newly created observers and reactive
#' expressions will be assigned to the current default domain (if any). You can
#' override this assignment by providing an explicit \code{domain} argument to
#' \code{\link{reactive}} or \code{\link{observe}}.
#'
#' For advanced usage, it's possible to override the default domain using
#' \code{withReactiveDomain}. The \code{domain} argument will be made the
#' default domain while \code{expr} is evaluated.
#'
#' Implementers of new reactive primitives can use \code{onReactiveDomainEnded}
#' as a convenience function for registering callbacks. If the reactive domain
#' is \code{NULL} and \code{failIfNull} is \code{FALSE}, then the callback will
#' never be invoked.
#'
#' @name domains
#' @param domain A valid domain object (for example, a Shiny session), or
#' \code{NULL}
#' @param expr An expression to evaluate under \code{domain}
#' @param callback A callback function to be invoked
#' @param failIfNull If \code{TRUE} then an error is given if the \code{domain}
#' is \code{NULL}
NULL
#
# Example 1
# ---
# ```
# obs1 <- observe({
# })
# shinyServer(function(input, output) {
# obs2 <- observe({
# obs3 <- observe({
# })
# })
# })
# # obs1 would have no domain, obs2 and obs3 would be owned by the session
# ```
#
# Example 2
# ---
# ```
# globalValues <- reactiveValues(broadcast="")
# shinyServer(function(input, output) {
# sessionValues <- reactiveValues()
# output$messageOutput <- renderText({
# globalValues$broadcast
# obs1 <- observe({...})
# })
# observe({
# if (input$goButton == 0) return()
# isolate( globalValues$broadcast <- input$messageInput )
# })
# })
# # The observer behind messageOutput would be owned by the session,
# # as would all the many instances of obs1 that were created.
# ```
# ---
#
# Example 3
# ---
# ```
# rexpr1 <- reactive({
# invalidateLater(1000)
# obs1 <- observe({...})
# })
# observeSomething <- function() {
# obs2 <- observe({...})
# })
# shinyServer(function(input, output) {
# obs3 <- observe({
# observeSomething()
# rexpr1()
# })
# })
# # rexpr1, the invalidateLater call, and obs1 would all have no owner;
# # obs2 and obs3 would be owned by the session.
# ```

1186
R/reactives.R Normal file

File diff suppressed because it is too large Load Diff

167
R/run-url.R Normal file
View File

@@ -0,0 +1,167 @@
#' Run a Shiny application from https://gist.github.com
#'
#' Download and launch a Shiny application that is hosted on GitHub as a gist.
#'
#' @param gist The identifier of the gist. For example, if the gist is
#' https://gist.github.com/jcheng5/3239667, then \code{3239667},
#' \code{'3239667'}, and \code{'https://gist.github.com/jcheng5/3239667'}
#' are all valid values.
#' @param port The TCP port that the application should listen on. Defaults to
#' choosing a random port.
#' @param launch.browser If true, the system's default web browser will be
#' launched automatically after the app is started. Defaults to true in
#' interactive sessions only.
#'
#' @examples
#' \dontrun{
#' runGist(3239667)
#' runGist("https://gist.github.com/jcheng5/3239667")
#'
#' # Old URL format without username
#' runGist("https://gist.github.com/3239667")
#' }
#'
#' @export
runGist <- function(gist,
port=NULL,
launch.browser=getOption('shiny.launch.browser',
interactive())) {
gistUrl <- if (is.numeric(gist) || grepl('^[0-9a-f]+$', gist)) {
sprintf('https://gist.github.com/%s/download', gist)
} else if(grepl('^https://gist.github.com/([^/]+/)?([0-9a-f]+)$', gist)) {
paste(gist, '/download', sep='')
} else {
stop('Unrecognized gist identifier format')
}
runUrl(gistUrl, filetype=".tar.gz", subdir=NULL, port=port,
launch.browser=launch.browser)
}
#' Run a Shiny application from a GitHub repository
#'
#' Download and launch a Shiny application that is hosted in a GitHub repository.
#'
#' @param repo Name of the repository
#' @param username GitHub username
#' @param ref Desired git reference. Could be a commit, tag, or branch
#' name. Defaults to \code{"master"}.
#' @param subdir A subdirectory in the repository that contains the app. By
#' default, this function will run an app from the top level of the repo, but
#' you can use a path such as `\code{"inst/shinyapp"}.
#' @param port The TCP port that the application should listen on. Defaults to
#' choosing a random port.
#' @param launch.browser If true, the system's default web browser will be
#' launched automatically after the app is started. Defaults to true in
#' interactive sessions only.
#'
#' @examples
#' \dontrun{
#' runGitHub("shiny_example", "rstudio")
#'
#' # Can run an app from a subdirectory in the repo
#' runGitHub("shiny_example", "rstudio", subdir = "inst/shinyapp/")
#' }
#'
#' @export
runGitHub <- function(repo, username = getOption("github.user"),
ref = "master", subdir = NULL, port = NULL,
launch.browser = getOption('shiny.launch.browser', interactive())) {
if (is.null(ref)) {
stop("Must specify either a ref. ")
}
message("Downloading github repo(s) ",
paste(repo, ref, sep = "/", collapse = ", "),
" from ",
paste(username, collapse = ", "))
name <- paste(username, "-", repo, sep = "")
url <- paste("https://github.com/", username, "/", repo, "/archive/",
ref, ".tar.gz", sep = "")
runUrl(url, subdir=subdir, port=port, launch.browser=launch.browser)
}
#' Run a Shiny application from a URL
#'
#' Download and launch a Shiny application that is hosted at a downloadable
#' URL. The Shiny application must be saved in a .zip, .tar, or .tar.gz file.
#' The Shiny application files must be contained in a subdirectory in the
#' archive. For example, the files might be \code{myapp/server.r} and
#' \code{myapp/ui.r}.
#'
#' @param url URL of the application.
#' @param filetype The file type (\code{".zip"}, \code{".tar"}, or
#' \code{".tar.gz"}. Defaults to the file extension taken from the url.
#' @param subdir A subdirectory in the repository that contains the app. By
#' default, this function will run an app from the top level of the repo, but
#' you can use a path such as `\code{"inst/shinyapp"}.
#' @param port The TCP port that the application should listen on. Defaults to
#' choosing a random port.
#' @param launch.browser If true, the system's default web browser will be
#' launched automatically after the app is started. Defaults to true in
#' interactive sessions only.
#'
#' @examples
#' \dontrun{
#' runUrl('https://github.com/rstudio/shiny_example/archive/master.tar.gz')
#'
#' # Can run an app from a subdirectory in the archive
#' runUrl("https://github.com/rstudio/shiny_example/archive/master.zip",
#' subdir = "inst/shinyapp/")
#' }
#'
#' @export
runUrl <- function(url, filetype = NULL, subdir = NULL, port = NULL,
launch.browser = getOption('shiny.launch.browser', interactive())) {
if (!is.null(subdir) && ".." %in% strsplit(subdir, '/')[[1]])
stop("'..' not allowed in subdir")
if (is.null(filetype))
filetype <- basename(url)
if (grepl("\\.tar\\.gz$", filetype))
fileext <- ".tar.gz"
else if (grepl("\\.tar$", filetype))
fileext <- ".tar"
else if (grepl("\\.zip$", filetype))
fileext <- ".zip"
else
stop("Unknown file extension.")
message("Downloading ", url)
filePath <- tempfile('shinyapp', fileext=fileext)
fileDir <- tempfile('shinyapp')
dir.create(fileDir, showWarnings = FALSE)
if (download(url, filePath, mode = "wb", quiet = TRUE) != 0)
stop("Failed to download URL ", url)
on.exit(unlink(filePath))
if (fileext %in% c(".tar", ".tar.gz")) {
# Regular untar commonly causes two problems on Windows with github tarballs:
# 1) If RTools' tar.exe is in the path, you get cygwin path warnings which
# throw list=TRUE off;
# 2) If the internal untar implementation is used, it chokes on the 'g'
# type flag that github uses (to stash their commit hash info).
# By using our own forked/modified untar2 we sidestep both issues.
first <- untar2(filePath, list=TRUE)[1]
untar2(filePath, exdir = fileDir)
} else if (fileext == ".zip") {
first <- as.character(unzip(filePath, list=TRUE)$Name)[1]
unzip(filePath, exdir = fileDir)
}
on.exit(unlink(fileDir, recursive = TRUE), add = TRUE)
appdir <- file.path(fileDir, first)
if (!file_test('-d', appdir)) appdir <- dirname(appdir)
if (!is.null(subdir)) appdir <- file.path(appdir, subdir)
runApp(appdir, port=port, launch.browser=launch.browser)
}

801
R/server.R Normal file
View File

@@ -0,0 +1,801 @@
#' @include globals.R
appsByToken <- Map$new()
# Create a map for input handlers and register the defaults.
inputHandlers <- Map$new()
#' Register an Input Handler
#'
#' Adds an input handler for data of this type. When called, Shiny will use the
#' function provided to refine the data passed back from the client (after being
#' deserialized by RJSONIO) before making it available in the \code{input}
#' variable of the \code{server.R} file.
#'
#' This function will register the handler for the duration of the R process
#' (unless Shiny is explicitly reloaded). For that reason, the \code{type} used
#' should be very specific to this package to minimize the risk of colliding
#' with another Shiny package which might use this data type name. We recommend
#' the format of "packageName.widgetName".
#'
#' Currently Shiny registers the following handlers: \code{shiny.matrix},
#' \code{shiny.number}, and \code{shiny.date}.
#'
#' The \code{type} of a custom Shiny Input widget will be deduced using the
#' \code{getType()} JavaScript function on the registered Shiny inputBinding.
#' @param type The type for which the handler should be added -- should be a
#' single-element character vector.
#' @param fun The handler function. This is the function that will be used to
#' parse the data delivered from the client before it is available in the
#' \code{input} variable. The function will be called with the following three
#' parameters:
#' \enumerate{
#' \item{The value of this input as provided by the client, deserialized
#' using RJSONIO.}
#' \item{The \code{shinysession} in which the input exists.}
#' \item{The name of the input.}
#' }
#' @param force If \code{TRUE}, will overwrite any existing handler without
#' warning. If \code{FALSE}, will throw an error if this class already has
#' a handler defined.
#' @examples
#' \dontrun{
#' # Register an input handler which rounds a input number to the nearest integer
#' registerInputHandler("mypackage.validint", function(x, shinysession, name) {
#' if (is.null(x)) return(NA)
#' round(x)
#' })
#'
#' ## On the Javascript side, the associated input binding must have a corresponding getType method:
#' getType: function(el) {
#' return "mypackage.validint";
#' }
#'
#' }
#' @seealso \code{\link{removeInputHandler}}
#' @export
registerInputHandler <- function(type, fun, force=FALSE){
if (inputHandlers$containsKey(type) && !force){
stop("There is already an input handler for type: ", type)
}
inputHandlers$set(type, fun)
}
#' Deregister an Input Handler
#'
#' Removes an Input Handler. Rather than using the previously specified handler
#' for data of this type, the default RJSONIO serialization will be used.
#'
#' @param type The type for which handlers should be removed.
#' @return The handler previously associated with this \code{type}, if one
#' existed. Otherwise, \code{NULL}.
#' @seealso \code{\link{registerInputHandler}}
#' @export
removeInputHandler <- function(type){
inputHandlers$remove(type)
}
# Takes a list-of-lists and returns a matrix. The lists
# must all be the same length. NULL is replaced by NA.
registerInputHandler("shiny.matrix", function(data, ...) {
if (length(data) == 0)
return(matrix(nrow=0, ncol=0))
m <- matrix(unlist(lapply(data, function(x) {
sapply(x, function(y) {
ifelse(is.null(y), NA, y)
})
})), nrow = length(data[[1]]), ncol = length(data))
return(m)
})
registerInputHandler("shiny.number", function(val, ...){
ifelse(is.null(val), NA, val)
})
registerInputHandler("shiny.date", function(val, ...){
# First replace NULLs with NA, then convert to Date vector
datelist <- ifelse(lapply(val, is.null), NA, val)
as.Date(unlist(datelist))
})
registerInputHandler("shiny.action", function(val, ...) {
# mark up the action button value with a special class so we can recognize it later
class(val) <- c(class(val), "shinyActionButtonValue")
val
})
# Provide a character representation of the WS that can be used
# as a key in a Map.
wsToKey <- function(WS) {
as.character(WS$socket)
}
.globals$clients <- function(req) NULL
clearClients <- function() {
.globals$clients <- function(req) NULL
}
registerClient <- function(client) {
.globals$clients <- append(.globals$clients, client)
}
.globals$resources <- list()
.globals$showcaseDefault <- 0
.globals$showcaseOverride <- FALSE
#' Resource Publishing
#'
#' Adds a directory of static resources to Shiny's web server, with the given
#' path prefix. Primarily intended for package authors to make supporting
#' JavaScript/CSS files available to their components.
#'
#' @param prefix The URL prefix (without slashes). Valid characters are a-z,
#' A-Z, 0-9, hyphen, period, and underscore; and must begin with a-z or A-Z.
#' For example, a value of 'foo' means that any request paths that begin with
#' '/foo' will be mapped to the given directory.
#' @param directoryPath The directory that contains the static resources to be
#' served.
#'
#' @details You can call \code{addResourcePath} multiple times for a given
#' \code{prefix}; only the most recent value will be retained. If the
#' normalized \code{directoryPath} is different than the directory that's
#' currently mapped to the \code{prefix}, a warning will be issued.
#'
#' @seealso \code{\link{singleton}}
#'
#' @examples
#' addResourcePath('datasets', system.file('data', package='datasets'))
#'
#' @export
addResourcePath <- function(prefix, directoryPath) {
prefix <- prefix[1]
if (!grepl('^[a-z][a-z0-9\\-_.]*$', prefix, ignore.case=TRUE, perl=TRUE)) {
stop("addResourcePath called with invalid prefix; please see documentation")
}
if (prefix %in% c('shared')) {
stop("addResourcePath called with the reserved prefix '", prefix, "'; ",
"please use a different prefix")
}
directoryPath <- normalizePath(directoryPath, mustWork=TRUE)
existing <- .globals$resources[[prefix]]
if (!is.null(existing)) {
if (!identical(existing$directoryPath, directoryPath)) {
warning("Overriding existing prefix ", prefix, " => ",
existing$directoryPath)
}
}
.globals$resources[[prefix]] <- list(directoryPath=directoryPath,
func=staticHandler(directoryPath))
}
resourcePathHandler <- function(req) {
if (!identical(req$REQUEST_METHOD, 'GET'))
return(NULL)
path <- req$PATH_INFO
match <- regexpr('^/([^/]+)/', path, perl=TRUE)
if (match == -1)
return(NULL)
len <- attr(match, 'capture.length')
prefix <- substr(path, 2, 2 + len - 1)
resInfo <- .globals$resources[[prefix]]
if (is.null(resInfo))
return(NULL)
suffix <- substr(path, 2 + len, nchar(path))
subreq <- as.environment(as.list(req, all.names=TRUE))
subreq$PATH_INFO <- suffix
subreq$SCRIPT_NAME <- paste(subreq$SCRIPT_NAME, substr(path, 1, 2 + len), sep='')
return(resInfo$func(subreq))
}
#' Define Server Functionality
#'
#' Defines the server-side logic of the Shiny application. This generally
#' involves creating functions that map user inputs to various kinds of output.
#'
#' @param func The server function for this application. See the details section
#' for more information.
#'
#' @details
#' Call \code{shinyServer} from your application's \code{server.R} file, passing
#' in a "server function" that provides the server-side logic of your
#' application.
#'
#' The server function will be called when each client (web browser) first loads
#' the Shiny application's page. It must take an \code{input} and an
#' \code{output} parameter. Any return value will be ignored. It also takes an
#' optional \code{session} parameter, which is used when greater control is
#' needed.
#'
#' See the \href{http://rstudio.github.com/shiny/tutorial/}{tutorial} for more
#' on how to write a server function.
#'
#' @examples
#' \dontrun{
#' # A very simple Shiny app that takes a message from the user
#' # and outputs an uppercase version of it.
#' shinyServer(function(input, output, session) {
#' output$uppercase <- renderText({
#' toupper(input$message)
#' })
#' })
#' }
#'
#' @export
shinyServer <- function(func) {
.globals$server <- list(func)
invisible(func)
}
decodeMessage <- function(data) {
readInt <- function(pos) {
packBits(rawToBits(data[pos:(pos+3)]), type='integer')
}
if (readInt(1) != 0x01020202L)
return(fromJSON(rawToChar(data), asText=TRUE, simplify=FALSE))
i <- 5
parts <- list()
while (i <= length(data)) {
length <- readInt(i)
i <- i + 4
if (length != 0)
parts <- append(parts, list(data[i:(i+length-1)]))
else
parts <- append(parts, list(raw(0)))
i <- i + length
}
mainMessage <- decodeMessage(parts[[1]])
mainMessage$blobs <- parts[2:length(parts)]
return(mainMessage)
}
createAppHandlers <- function(httpHandlers, serverFuncSource) {
appvars <- new.env()
appvars$server <- NULL
sys.www.root <- system.file('www', package='shiny')
# This value, if non-NULL, must be present on all HTTP and WebSocket
# requests as the Shiny-Shared-Secret header or else access will be
# denied (403 response for HTTP, and instant close for websocket).
sharedSecret <- getOption('shiny.sharedSecret', NULL)
appHandlers <- list(
http = joinHandlers(c(
sessionHandler,
httpHandlers,
sys.www.root,
resourcePathHandler,
reactLogHandler)),
ws = function(ws) {
if (!is.null(sharedSecret)
&& !identical(sharedSecret, ws$request$HTTP_SHINY_SHARED_SECRET)) {
ws$close()
return(TRUE)
}
shinysession <- ShinySession$new(ws)
appsByToken$set(shinysession$token, shinysession)
shinysession$setShowcase(.globals$showcaseDefault)
ws$onMessage(function(binary, msg) {
# To ease transition from websockets-based code. Should remove once we're stable.
if (is.character(msg))
msg <- charToRaw(msg)
if (getOption('shiny.trace', FALSE)) {
if (binary)
message("RECV ", '$$binary data$$')
else
message("RECV ", rawToChar(msg))
}
if (identical(charToRaw("\003\xe9"), msg))
return()
msg <- decodeMessage(msg)
# Do our own list simplifying here. sapply/simplify2array give names to
# character vectors, which is rarely what we want.
if (!is.null(msg$data)) {
for (name in names(msg$data)) {
val <- msg$data[[name]]
splitName <- strsplit(name, ':')[[1]]
if (length(splitName) > 1) {
msg$data[[name]] <- NULL
if (!inputHandlers$containsKey(splitName[[2]])){
# No input handler registered for this type
stop("No handler registered for for type ", name)
}
msg$data[[ splitName[[1]] ]] <-
inputHandlers$get(splitName[[2]])(
val,
shinysession,
splitName[[1]] )
}
else if (is.list(val) && is.null(names(val))) {
val_flat <- unlist(val, recursive = TRUE)
if (is.null(val_flat)) {
# This is to assign NULL instead of deleting the item
msg$data[name] <- list(NULL)
} else {
msg$data[[name]] <- val_flat
}
}
}
}
switch(
msg$method,
init = {
serverFunc <- serverFuncSource()
if (!identicalFunctionBodies(serverFunc, appvars$server)) {
appvars$server <- serverFunc
if (!is.null(appvars$server))
{
# Tag this function as the Shiny server function. A debugger may use this
# tag to give this function special treatment.
# It's very important that it's appvars$server itself and NOT a copy that
# is invoked, otherwise new breakpoints won't be picked up.
attr(appvars$server, "shinyServerFunction") <- TRUE
registerDebugHook("server", appvars, "Server Function")
}
}
# Check for switching into/out of showcase mode
if (.globals$showcaseOverride &&
exists(".clientdata_url_search", where = msg$data)) {
mode <- showcaseModeOfQuerystring(msg$data$.clientdata_url_search)
if (!is.null(mode))
shinysession$setShowcase(mode)
}
shinysession$manageInputs(msg$data)
# The client tells us what singletons were rendered into
# the initial page
if (!is.null(msg$data$.clientdata_singletons)) {
shinysession$singletons <<- strsplit(
msg$data$.clientdata_singletons, ',')[[1]]
}
local({
args <- list(
input=shinysession$input,
output=.createOutputWriter(shinysession))
# The clientData and session arguments are optional; check if
# each exists
if ('clientData' %in% names(formals(serverFunc)))
args$clientData <- shinysession$clientData
if ('session' %in% names(formals(serverFunc)))
args$session <- shinysession$session
withReactiveDomain(shinysession$session, {
do.call(appvars$server, args)
})
})
},
update = {
shinysession$manageInputs(msg$data)
},
shinysession$dispatch(msg)
)
shinysession$manageHiddenOutputs()
if (exists(".shiny__stdout", globalenv()) &&
exists("HTTP_GUID", ws$request)) {
# safe to assume we're in shiny-server
shiny_stdout <- get(".shiny__stdout", globalenv())
# eNter a flushReact
writeLines(paste("_n_flushReact ", get("HTTP_GUID", ws$request),
" @ ", sprintf("%.3f", as.numeric(Sys.time())),
sep=""), con=shiny_stdout)
flush(shiny_stdout)
flushReact()
# eXit a flushReact
writeLines(paste("_x_flushReact ", get("HTTP_GUID", ws$request),
" @ ", sprintf("%.3f", as.numeric(Sys.time())),
sep=""), con=shiny_stdout)
flush(shiny_stdout)
} else {
flushReact()
}
lapply(appsByToken$values(), function(shinysession) {
shinysession$flushOutput()
NULL
})
})
ws$onClose(function() {
shinysession$close()
appsByToken$remove(shinysession$token)
})
return(TRUE)
}
)
return(appHandlers)
}
getEffectiveBody <- function(func) {
# Note: NULL values are OK. isS4(NULL) returns FALSE, body(NULL)
# returns NULL.
if (isS4(func) && class(func) == "functionWithTrace")
body(func@original)
else
body(func)
}
identicalFunctionBodies <- function(a, b) {
identical(getEffectiveBody(a), getEffectiveBody(b))
}
handlerManager <- HandlerManager$new()
addSubApp <- function(appObj, autoRemove = TRUE) {
path <- createUniqueId(16, "/app")
appHandlers <- createAppHandlers(appObj$httpHandler, appObj$serverFuncSource)
# remove the leading / from the path so a relative path is returned
# (needed for the case where the root URL for the Shiny app isn't /, such
# as portmapped URLs)
finalPath <- paste(
substr(path, 2, nchar(path)),
"/?w=", workerId(),
"&__subapp__=1",
sep="")
handlerManager$addHandler(routeHandler(path, appHandlers$http), finalPath)
handlerManager$addWSHandler(routeWSHandler(path, appHandlers$ws), finalPath)
if (autoRemove) {
# If a session is currently active, remove this subapp automatically when
# the current session ends
onReactiveDomainEnded(getDefaultReactiveDomain(), function() {
removeSubApp(finalPath)
})
}
return(finalPath)
}
removeSubApp <- function(path) {
handlerManager$removeHandler(path)
handlerManager$removeWSHandler(path)
}
startApp <- function(appObj, port, host, quiet) {
appHandlers <- createAppHandlers(appObj$httpHandler, appObj$serverFuncSource)
handlerManager$addHandler(appHandlers$http, "/", tail = TRUE)
handlerManager$addWSHandler(appHandlers$ws, "/", tail = TRUE)
if (is.numeric(port) || is.integer(port)) {
if (!quiet) {
message('\n', 'Listening on http://', host, ':', port)
}
return(startServer(host, port, handlerManager$createHttpuvApp()))
} else if (is.character(port)) {
if (!quiet) {
message('\n', 'Listening on domain socket ', port)
}
mask <- attr(port, 'mask')
return(startPipeServer(port, mask, handlerManager$createHttpuvApp()))
}
}
# Run an application that was created by \code{\link{startApp}}. This
# function should normally be called in a \code{while(TRUE)} loop.
serviceApp <- function() {
if (timerCallbacks$executeElapsed()) {
for (shinysession in appsByToken$values()) {
shinysession$manageHiddenOutputs()
}
flushReact()
for (shinysession in appsByToken$values()) {
shinysession$flushOutput()
}
}
# If this R session is interactive, then call service() with a short timeout
# to keep the session responsive to user input
maxTimeout <- ifelse(interactive(), 100, 1000)
timeout <- max(1, min(maxTimeout, timerCallbacks$timeToNextEvent()))
service(timeout)
}
.shinyServerMinVersion <- '0.3.4'
#' Run Shiny Application
#'
#' Runs a Shiny application. This function normally does not return; interrupt
#' R to stop the application (usually by pressing Ctrl+C or Esc).
#'
#' The host parameter was introduced in Shiny 0.9.0. Its default value of
#' \code{"127.0.0.1"} means that, contrary to previous versions of Shiny, only
#' the current machine can access locally hosted Shiny apps. To allow other
#' clients to connect, use the value \code{"0.0.0.0"} instead (which was the
#' value that was hard-coded into Shiny in 0.8.0 and earlier).
#'
#' @param appDir The directory of the application. Should contain
#' \code{server.R}, plus, either \code{ui.R} or a \code{www} directory that
#' contains the file \code{index.html}. Defaults to the working directory.
#' @param port The TCP port that the application should listen on. Defaults to
#' choosing a random port.
#' @param launch.browser If true, the system's default web browser will be
#' launched automatically after the app is started. Defaults to true in
#' interactive sessions only. This value of this parameter can also be a
#' function to call with the application's URL.
#' @param host The IPv4 address that the application should listen on. Defaults
#' to the \code{shiny.host} option, if set, or \code{"127.0.0.1"} if not. See
#' Details.
#' @param workerId Can generally be ignored. Exists to help some editions of
#' Shiny Server Pro route requests to the correct process.
#' @param quiet Should Shiny status messages be shown? Defaults to FALSE.
#' @param display.mode The mode in which to display the application. If set to
#' the value \code{"showcase"}, shows application code and metadata from a
#' \code{DESCRIPTION} file in the application directory alongside the
#' application. If set to \code{"normal"}, displays the application normally.
#' Defaults to \code{"auto"}, which displays the application in the mode
#' given in its \code{DESCRIPTION} file, if any.
#'
#' @examples
#' \dontrun{
#' # Start app in the current working directory
#' runApp()
#'
#' # Start app in a subdirectory called myapp
#' runApp("myapp")
#'
#'
#' # Apps can be run without a server.r and ui.r file
#' runApp(list(
#' ui = bootstrapPage(
#' numericInput('n', 'Number of obs', 100),
#' plotOutput('plot')
#' ),
#' server = function(input, output) {
#' output$plot <- renderPlot({ hist(runif(input$n)) })
#' }
#' ))
#' }
#' @export
runApp <- function(appDir=getwd(),
port=NULL,
launch.browser=getOption('shiny.launch.browser',
interactive()),
host=getOption('shiny.host', '127.0.0.1'),
workerId="", quiet=FALSE,
display.mode=c("auto", "normal", "showcase")) {
on.exit({
handlerManager$clear()
}, add = TRUE)
if (is.null(host) || is.na(host))
host <- '0.0.0.0'
# Make warnings print immediately
ops <- options(warn = 1)
on.exit(options(ops), add = TRUE)
workerId(workerId)
if (nzchar(Sys.getenv('SHINY_PORT'))) {
# If SHINY_PORT is set, we're running under Shiny Server. Check the version
# to make sure it is compatible. Older versions of Shiny Server don't set
# SHINY_SERVER_VERSION, those will return "" which is considered less than
# any valid version.
ver <- Sys.getenv('SHINY_SERVER_VERSION')
if (compareVersion(ver, .shinyServerMinVersion) < 0) {
warning('Shiny Server v', .shinyServerMinVersion,
' or later is required; please upgrade!')
}
}
# Showcase mode is disabled by default; it must be explicitly enabled in
# either the DESCRIPTION file for directory-based apps, or via
# the display.mode parameter. The latter takes precedence.
setShowcaseDefault(0)
# If appDir specifies a path, and display mode is specified in the
# DESCRIPTION file at that path, apply it here.
if (is.character(appDir)) {
desc <- file.path.ci(appDir, "DESCRIPTION")
if (file.exists(desc)) {
settings <- read.dcf(desc)
if ("DisplayMode" %in% colnames(settings)) {
mode <- settings[1,"DisplayMode"]
if (mode == "Showcase") {
setShowcaseDefault(1)
}
}
}
}
# If display mode is specified as an argument, apply it (overriding the
# value specified in DESCRIPTION, if any).
display.mode <- match.arg(display.mode)
if (display.mode == "normal")
setShowcaseDefault(0)
else if (display.mode == "showcase")
setShowcaseDefault(1)
require(shiny)
# determine port if we need to
if (is.null(port)) {
# Try up to 20 random ports. If we don't succeed just plow ahead
# with the final value we tried, and let the "real" startServer
# somewhere down the line fail and throw the error to the user.
#
# If we (think we) succeed, save the value as .globals$lastPort,
# and try that first next time the user wants a random port.
for (i in 1:20) {
if (!is.null(.globals$lastPort)) {
port <- .globals$lastPort
.globals$lastPort <- NULL
}
else {
# Try up to 20 random ports
port <- p_randomInt(3000, 8000)
}
# Test port to see if we can use it
tmp <- try(startServer(host, port, list()), silent=TRUE)
if (!inherits(tmp, 'try-error')) {
stopServer(tmp)
.globals$lastPort <- port
break
}
}
}
appParts <- as.shiny.appobj(appDir)
if (!is.null(appParts$onStart))
appParts$onStart()
if (!is.null(appParts$onEnd))
on.exit(appParts$onEnd(), add = TRUE)
server <- startApp(appParts, port, host, quiet)
on.exit({
stopServer(server)
}, add = TRUE)
if (!is.character(port)) {
# http://0.0.0.0/ doesn't work on QtWebKit (i.e. RStudio viewer)
browseHost <- if (identical(host, "0.0.0.0")) "127.0.0.1" else host
appUrl <- paste("http://", browseHost, ":", port, sep="")
if (is.function(launch.browser))
launch.browser(appUrl)
else if (launch.browser)
utils::browseURL(appUrl)
} else {
appUrl <- NULL
}
# call application hooks
callAppHook("onAppStart", appUrl)
on.exit({
callAppHook("onAppStop", appUrl)
}, add = TRUE)
.globals$retval <- NULL
.globals$stopped <- FALSE
shinyCallingHandlers(
while (!.globals$stopped) {
serviceApp()
Sys.sleep(0.001)
}
)
return(.globals$retval)
}
#' Stop the currently running Shiny app
#'
#' Stops the currently running Shiny app, returning control to the caller of
#' \code{\link{runApp}}.
#'
#' @param returnValue The value that should be returned from
#' \code{\link{runApp}}.
#'
#' @export
stopApp <- function(returnValue = NULL) {
.globals$retval <- returnValue
.globals$stopped <- TRUE
httpuv::interrupt()
}
#' Run Shiny Example Applications
#'
#' Launch Shiny example applications, and optionally, your system's web browser.
#'
#' @param example The name of the example to run, or \code{NA} (the default) to
#' list the available examples.
#' @param port The TCP port that the application should listen on. Defaults to
#' choosing a random port.
#' @param launch.browser If true, the system's default web browser will be
#' launched automatically after the app is started. Defaults to true in
#' interactive sessions only.
#' @param host The IPv4 address that the application should listen on. Defaults
#' to the \code{shiny.host} option, if set, or \code{"127.0.0.1"} if not.
#' @param display.mode The mode in which to display the example. Defaults to
#' \code{showcase}, but may be set to \code{normal} to see the example without
#' code or commentary.
#'
#' @examples
#' \dontrun{
#' # List all available examples
#' runExample()
#'
#' # Run one of the examples
#' runExample("01_hello")
#'
#' # Print the directory containing the code for all examples
#' system.file("examples", package="shiny")
#' }
#' @export
runExample <- function(example=NA,
port=NULL,
launch.browser=getOption('shiny.launch.browser',
interactive()),
host=getOption('shiny.host', '127.0.0.1'),
display.mode=c("auto", "normal", "showcase")) {
examplesDir <- system.file('examples', package='shiny')
dir <- resolve(examplesDir, example)
if (is.null(dir)) {
if (is.na(example)) {
errFun <- message
errMsg <- ''
}
else {
errFun <- stop
errMsg <- paste('Example', example, 'does not exist. ')
}
errFun(errMsg,
'Valid examples are "',
paste(list.files(examplesDir), collapse='", "'),
'"')
}
else {
runApp(dir, port = port, host = host, launch.browser = launch.browser,
display.mode = display.mode)
}
}

997
R/shiny.R

File diff suppressed because it is too large Load Diff

133
R/shinyui.R Normal file
View File

@@ -0,0 +1,133 @@
#' @include globals.R
NULL
#' Load the MathJax library and typeset math expressions
#'
#' This function adds MathJax to the page and typeset the math expressions (if
#' found) in the content \code{...}. It only needs to be called once in an app
#' unless the content is rendered \emph{after} the page is loaded, e.g. via
#' \code{\link{renderUI}}, in which case we have to call it explicitly every
#' time we write math expressions to the output.
#' @param ... any HTML elements to apply MathJax to
#' @export
#' @examples withMathJax(helpText("Some math here $$\\alpha+\\beta$$"))
#' # now we can just write "static" content without withMathJax()
#' div("more math here $$\\sqrt{2}$$")
withMathJax <- function(...) {
path <- 'https://c328740.ssl.cf1.rackcdn.com/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'
tagList(
tags$head(
singleton(tags$script(src = path, type = 'text/javascript'))
),
...,
tags$script(HTML('MathJax.Hub.Queue(["Typeset", MathJax.Hub]);'))
)
}
renderPage <- function(ui, connection, showcase=0) {
if (showcase > 0)
ui <- tagList(tags$head(showcaseHead()), ui)
result <- renderTags(ui)
deps <- c(
list(
htmlDependency("jquery", "1.11.0", c(href="shared"), script = "jquery.js"),
htmlDependency("shiny", packageVersion("shiny"), c(href="shared"),
script = "shiny.js", stylesheet = "shiny.css")
),
result$dependencies
)
deps <- resolveDependencies(deps)
deps <- lapply(deps, createWebDependency)
depStr <- paste(sapply(deps, function(dep) {
sprintf("%s[%s]", dep$name, dep$version)
}), collapse = ";")
depHtml <- renderDependencies(deps, "href")
# write preamble
writeLines(c('<!DOCTYPE html>',
'<html>',
'<head>',
' <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>',
sprintf(' <script type="application/shiny-singletons">%s</script>',
paste(result$singletons, collapse = ',')
),
sprintf(' <script type="application/html-dependencies">%s</script>',
depStr
),
depHtml
),
con = connection)
writeLines(c(result$head,
'</head>',
'<body>',
recursive=TRUE),
con = connection)
if (showcase > 0) {
# in showcase mode, emit containing elements and app HTML
writeLines(as.character(showcaseBody(result$html)),
con = connection)
} else {
# in normal mode, write UI html directly to connection
writeLines(result$html, con = connection)
}
# write end document
writeLines(c('</body>',
'</html>'),
con = connection)
}
#' Create a Shiny UI handler
#'
#' Historically this function was used in ui.R files to register a user
#' interface with Shiny. It is no longer required; simply ensure that the last
#' expression to be returned from ui.R is a user interface. This function is
#' kept for backwards compatibility with older applications. It returns the
#' value that is passed to it.
#'
#' @param ui A user interace definition
#' @return The user interface definition, without modifications or side effects.
#'
#' @export
shinyUI <- function(ui) {
.globals$ui <- list(ui)
ui
}
uiHttpHandler <- function(ui, path = "/") {
force(ui)
function(req) {
if (!identical(req$REQUEST_METHOD, 'GET'))
return(NULL)
if (req$PATH_INFO != path)
return(NULL)
textConn <- textConnection(NULL, "w")
on.exit(close(textConn))
showcaseMode <- .globals$showcaseDefault
if (.globals$showcaseOverride) {
mode <- showcaseModeOfReq(req)
if (!is.null(mode))
showcaseMode <- mode
}
uiValue <- if (is.function(ui)) {
if (length(formals(ui)) > 0)
ui(req)
else
ui()
}
else
ui
renderPage(uiValue, textConn, showcaseMode)
html <- paste(textConnectionValue(textConn), collapse='\n')
return(httpResponse(200, content=html))
}
}

631
R/shinywrappers.R Normal file
View File

@@ -0,0 +1,631 @@
globalVariables('func')
#' Mark a function as a render function
#'
#' Should be called by implementers of \code{renderXXX} functions in order to
#' mark their return values as Shiny render functions, and to provide a hint to
#' Shiny regarding what UI function is most commonly used with this type of
#' render function. This can be used in R Markdown documents to create complete
#' output widgets out of just the render function.
#'
#' @param uiFunc A function that renders Shiny UI. Must take a single argument:
#' an output ID.
#' @param renderFunc A function that is suitable for assigning to a Shiny output
#' slot.
#' @return The \code{renderFunc} function, with annotations.
#'
#' @export
markRenderFunction <- function(uiFunc, renderFunc) {
class(renderFunc) <- c("shiny.render.function", "function")
attr(renderFunc, "outputFunc") <- uiFunc
renderFunc
}
useRenderFunction <- function(renderFunc) {
outputFunction <- attr(renderFunc, "outputFunc")
id <- createUniqueId(8, "out")
o <- getDefaultReactiveDomain()$output
if (!is.null(o))
o[[id]] <- renderFunc
return(outputFunction(id))
}
#' @S3method as.tags shiny.render.function
as.tags.shiny.render.function <- function(x, ...) {
useRenderFunction(x)
}
#' Plot Output
#'
#' Renders a reactive plot that is suitable for assigning to an \code{output}
#' slot.
#'
#' The corresponding HTML output tag should be \code{div} or \code{img} and have
#' the CSS class name \code{shiny-plot-output}.
#'
#' @seealso For more details on how the plots are generated, and how to control
#' the output, see \code{\link{plotPNG}}.
#'
#' @param expr An expression that generates a plot.
#' @param width The width of the rendered plot, in pixels; or \code{'auto'} to
#' use the \code{offsetWidth} of the HTML element that is bound to this plot.
#' You can also pass in a function that returns the width in pixels or
#' \code{'auto'}; in the body of the function you may reference reactive
#' values and functions.
#' @param height The height of the rendered plot, in pixels; or \code{'auto'} to
#' use the \code{offsetHeight} of the HTML element that is bound to this plot.
#' You can also pass in a function that returns the width in pixels or
#' \code{'auto'}; in the body of the function you may reference reactive
#' values and functions.
#' @param res Resolution of resulting plot, in pixels per inch. This value is
#' passed to \code{\link{png}}. Note that this affects the resolution of PNG
#' rendering in R; it won't change the actual ppi of the browser.
#' @param ... Arguments to be passed through to \code{\link[grDevices]{png}}.
#' These can be used to set the width, height, background color, etc.
#' @param env The environment in which to evaluate \code{expr}.
#' @param quoted Is \code{expr} a quoted expression (with \code{quote()})? This
#' is useful if you want to save an expression in a variable.
#' @param func A function that generates a plot (deprecated; use \code{expr}
#' instead).
#'
#' @export
renderPlot <- function(expr, width='auto', height='auto', res=72, ...,
env=parent.frame(), quoted=FALSE, func=NULL) {
if (!is.null(func)) {
shinyDeprecated(msg="renderPlot: argument 'func' is deprecated. Please use 'expr' instead.")
} else {
installExprFunction(expr, "func", env, quoted)
}
args <- list(...)
if (is.function(width))
widthWrapper <- reactive({ width() })
else
widthWrapper <- NULL
if (is.function(height))
heightWrapper <- reactive({ height() })
else
heightWrapper <- NULL
# If renderPlot isn't going to adapt to the height of the div, then the
# div needs to adapt to the height of renderPlot. By default, plotOutput
# sets the height to 400px, so to make it adapt we need to override it
# with NULL.
outputFunc <- if (identical(height, 'auto'))
plotOutput
else
function(outputId) plotOutput(outputId, height = NULL)
return(markRenderFunction(outputFunc, function(shinysession, name, ...) {
if (!is.null(widthWrapper))
width <- widthWrapper()
if (!is.null(heightWrapper))
height <- heightWrapper()
# Note that these are reactive calls. A change to the width and height
# will inherently cause a reactive plot to redraw (unless width and
# height were explicitly specified).
prefix <- 'output_'
if (width == 'auto')
width <- shinysession$clientData[[paste(prefix, name, '_width', sep='')]];
if (height == 'auto')
height <- shinysession$clientData[[paste(prefix, name, '_height', sep='')]];
if (is.null(width) || is.null(height) || width <= 0 || height <= 0)
return(NULL)
# Resolution multiplier
pixelratio <- shinysession$clientData$pixelratio
if (is.null(pixelratio))
pixelratio <- 1
coordmap <- NULL
plotFunc <- function() {
# Actually perform the plotting
result <- withVisible(func())
if (result$visible) {
# Use capture.output to squelch printing to the actual console; we
# are only interested in plot output
capture.output(print(result$value))
}
# Now capture some graphics device info before we close it
usrCoords <- par('usr')
usrBounds <- usrCoords
if (par('xlog')) {
usrBounds[c(1,2)] <- 10 ^ usrBounds[c(1,2)]
}
if (par('ylog')) {
usrBounds[c(3,4)] <- 10 ^ usrBounds[c(3,4)]
}
coordmap <<- list(
usr = c(
left = usrCoords[1],
right = usrCoords[2],
bottom = usrCoords[3],
top = usrCoords[4]
),
# The bounds of the plot area, in DOM pixels
bounds = c(
left = grconvertX(usrBounds[1], 'user', 'nfc') * width,
right = grconvertX(usrBounds[2], 'user', 'nfc') * width,
bottom = (1-grconvertY(usrBounds[3], 'user', 'nfc')) * height,
top = (1-grconvertY(usrBounds[4], 'user', 'nfc')) * height
),
log = c(
x = par('xlog'),
y = par('ylog')
),
pixelratio = pixelratio
)
}
outfile <- do.call(plotPNG, c(plotFunc, width=width*pixelratio,
height=height*pixelratio, res=res*pixelratio, args))
on.exit(unlink(outfile))
# Return a list of attributes for the img
return(list(
src=shinysession$fileUrl(name, outfile, contentType='image/png'),
width=width, height=height, coordmap=coordmap
))
}))
}
#' Image file output
#'
#' Renders a reactive image that is suitable for assigning to an \code{output}
#' slot.
#'
#' The expression \code{expr} must return a list containing the attributes for
#' the \code{img} object on the client web page. For the image to display,
#' properly, the list must have at least one entry, \code{src}, which is the
#' path to the image file. It may also useful to have a \code{contentType}
#' entry specifying the MIME type of the image. If one is not provided,
#' \code{renderImage} will try to autodetect the type, based on the file
#' extension.
#'
#' Other elements such as \code{width}, \code{height}, \code{class}, and
#' \code{alt}, can also be added to the list, and they will be used as
#' attributes in the \code{img} object.
#'
#' The corresponding HTML output tag should be \code{div} or \code{img} and have
#' the CSS class name \code{shiny-image-output}.
#'
#' @seealso For more details on how the images are generated, and how to control
#' the output, see \code{\link{plotPNG}}.
#'
#' @param expr An expression that returns a list.
#' @param env The environment in which to evaluate \code{expr}.
#' @param quoted Is \code{expr} a quoted expression (with \code{quote()})? This
#' is useful if you want to save an expression in a variable.
#' @param deleteFile Should the file in \code{func()$src} be deleted after
#' it is sent to the client browser? Generally speaking, if the image is a
#' temp file generated within \code{func}, then this should be \code{TRUE};
#' if the image is not a temp file, this should be \code{FALSE}.
#'
#' @export
#'
#' @examples
#' \dontrun{
#'
#' shinyServer(function(input, output, clientData) {
#'
#' # A plot of fixed size
#' output$plot1 <- renderImage({
#' # A temp file to save the output. It will be deleted after renderImage
#' # sends it, because deleteFile=TRUE.
#' outfile <- tempfile(fileext='.png')
#'
#' # Generate a png
#' png(outfile, width=400, height=400)
#' hist(rnorm(input$n))
#' dev.off()
#'
#' # Return a list
#' list(src = outfile,
#' alt = "This is alternate text")
#' }, deleteFile = TRUE)
#'
#' # A dynamically-sized plot
#' output$plot2 <- renderImage({
#' # Read plot2's width and height. These are reactive values, so this
#' # expression will re-run whenever these values change.
#' width <- clientData$output_plot2_width
#' height <- clientData$output_plot2_height
#'
#' # A temp file to save the output.
#' outfile <- tempfile(fileext='.png')
#'
#' png(outfile, width=width, height=height)
#' hist(rnorm(input$obs))
#' dev.off()
#'
#' # Return a list containing the filename
#' list(src = outfile,
#' width = width,
#' height = height,
#' alt = "This is alternate text")
#' }, deleteFile = TRUE)
#'
#' # Send a pre-rendered image, and don't delete the image after sending it
#' output$plot3 <- renderImage({
#' # When input$n is 1, filename is ./images/image1.jpeg
#' filename <- normalizePath(file.path('./images',
#' paste('image', input$n, '.jpeg', sep='')))
#'
#' # Return a list containing the filename
#' list(src = filename)
#' }, deleteFile = FALSE)
#' })
#'
#' }
renderImage <- function(expr, env=parent.frame(), quoted=FALSE,
deleteFile=TRUE) {
installExprFunction(expr, "func", env, quoted)
return(markRenderFunction(imageOutput, function(shinysession, name, ...) {
imageinfo <- func()
# Should the file be deleted after being sent? If .deleteFile not set or if
# TRUE, then delete; otherwise don't delete.
if (deleteFile) {
on.exit(unlink(imageinfo$src))
}
# If contentType not specified, autodetect based on extension
if (is.null(imageinfo$contentType)) {
contentType <- getContentType(sub('^.*\\.', '', basename(imageinfo$src)))
} else {
contentType <- imageinfo$contentType
}
# Extra values are everything in imageinfo except 'src' and 'contentType'
extra_attr <- imageinfo[!names(imageinfo) %in% c('src', 'contentType')]
# Return a list with src, and other img attributes
c(src = shinysession$fileUrl(name, file=imageinfo$src, contentType=contentType),
extra_attr)
}))
}
#' Table Output
#'
#' Creates a reactive table that is suitable for assigning to an \code{output}
#' slot.
#'
#' The corresponding HTML output tag should be \code{div} and have the CSS class
#' name \code{shiny-html-output}.
#'
#' @param expr An expression that returns an R object that can be used with
#' \code{\link[xtable]{xtable}}.
#' @param ... Arguments to be passed through to \code{\link[xtable]{xtable}} and
#' \code{\link[xtable]{print.xtable}}.
#' @param env The environment in which to evaluate \code{expr}.
#' @param quoted Is \code{expr} a quoted expression (with \code{quote()})? This
#' is useful if you want to save an expression in a variable.
#' @param func A function that returns an R object that can be used with
#' \code{\link[xtable]{xtable}} (deprecated; use \code{expr} instead).
#'
#' @export
renderTable <- function(expr, ..., env=parent.frame(), quoted=FALSE, func=NULL) {
if (!is.null(func)) {
shinyDeprecated(msg="renderTable: argument 'func' is deprecated. Please use 'expr' instead.")
} else {
installExprFunction(expr, "func", env, quoted)
}
markRenderFunction(tableOutput, function() {
classNames <- getOption('shiny.table.class', 'data table table-bordered table-condensed')
data <- func()
if (is.null(data) || identical(data, data.frame()))
return("")
return(paste(
capture.output(
print(xtable(data, ...),
type='html',
html.table.attributes=paste('class="',
htmlEscape(classNames, TRUE),
'"',
sep=''), ...)),
collapse="\n"))
})
}
#' Printable Output
#'
#' Makes a reactive version of the given function that captures any printed
#' output, and also captures its printable result (unless
#' \code{\link{invisible}}), into a string. The resulting function is suitable
#' for assigning to an \code{output} slot.
#'
#' The corresponding HTML output tag can be anything (though \code{pre} is
#' recommended if you need a monospace font and whitespace preserved) and should
#' have the CSS class name \code{shiny-text-output}.
#'
#' The result of executing \code{func} will be printed inside a
#' \code{\link[utils]{capture.output}} call.
#'
#' Note that unlike most other Shiny output functions, if the given function
#' returns \code{NULL} then \code{NULL} will actually be visible in the output.
#' To display nothing, make your function return \code{\link{invisible}()}.
#'
#' @param expr An expression that may print output and/or return a printable R
#' object.
#' @param env The environment in which to evaluate \code{expr}.
#' @param quoted Is \code{expr} a quoted expression (with \code{quote()})? This
#' @param func A function that may print output and/or return a printable R
#' object (deprecated; use \code{expr} instead).
#' @param width The value for \code{\link{options}('width')}.
#' @seealso \code{\link{renderText}} for displaying the value returned from a
#' function, instead of the printed output.
#'
#' @example res/text-example.R
#'
#' @export
renderPrint <- function(expr, env = parent.frame(), quoted = FALSE, func = NULL,
width = getOption('width')) {
if (!is.null(func)) {
shinyDeprecated(msg="renderPrint: argument 'func' is deprecated. Please use 'expr' instead.")
} else {
installExprFunction(expr, "func", env, quoted)
}
markRenderFunction(verbatimTextOutput, function() {
op <- options(width = width)
on.exit(options(op), add = TRUE)
paste(capture.output(func()), collapse = "\n")
})
}
#' Text Output
#'
#' Makes a reactive version of the given function that also uses
#' \code{\link[base]{cat}} to turn its result into a single-element character
#' vector.
#'
#' The corresponding HTML output tag can be anything (though \code{pre} is
#' recommended if you need a monospace font and whitespace preserved) and should
#' have the CSS class name \code{shiny-text-output}.
#'
#' The result of executing \code{func} will passed to \code{cat}, inside a
#' \code{\link[utils]{capture.output}} call.
#'
#' @param expr An expression that returns an R object that can be used as an
#' argument to \code{cat}.
#' @param env The environment in which to evaluate \code{expr}.
#' @param quoted Is \code{expr} a quoted expression (with \code{quote()})? This
#' is useful if you want to save an expression in a variable.
#' @param func A function that returns an R object that can be used as an
#' argument to \code{cat}.(deprecated; use \code{expr} instead).
#'
#' @seealso \code{\link{renderPrint}} for capturing the print output of a
#' function, rather than the returned text value.
#'
#' @example res/text-example.R
#'
#' @export
renderText <- function(expr, env=parent.frame(), quoted=FALSE, func=NULL) {
if (!is.null(func)) {
shinyDeprecated(msg="renderText: argument 'func' is deprecated. Please use 'expr' instead.")
} else {
installExprFunction(expr, "func", env, quoted)
}
markRenderFunction(textOutput, function() {
value <- func()
return(paste(capture.output(cat(value)), collapse="\n"))
})
}
#' UI Output
#'
#' \bold{Experimental feature.} Makes a reactive version of a function that
#' generates HTML using the Shiny UI library.
#'
#' The corresponding HTML output tag should be \code{div} and have the CSS class
#' name \code{shiny-html-output} (or use \code{\link{uiOutput}}).
#'
#' @param expr An expression that returns a Shiny tag object, \code{\link{HTML}},
#' or a list of such objects.
#' @param env The environment in which to evaluate \code{expr}.
#' @param quoted Is \code{expr} a quoted expression (with \code{quote()})? This
#' is useful if you want to save an expression in a variable.
#' @param func A function that returns a Shiny tag object, \code{\link{HTML}},
#' or a list of such objects (deprecated; use \code{expr} instead).
#'
#' @seealso conditionalPanel
#'
#' @export
#' @examples
#' \dontrun{
#' output$moreControls <- renderUI({
#' list(
#'
#' )
#' })
#' }
renderUI <- function(expr, env=parent.frame(), quoted=FALSE, func=NULL) {
if (!is.null(func)) {
shinyDeprecated(msg="renderUI: argument 'func' is deprecated. Please use 'expr' instead.")
} else {
installExprFunction(expr, "func", env, quoted)
}
markRenderFunction(uiOutput, function(shinysession, name, ...) {
result <- func()
if (is.null(result) || length(result) == 0)
return(NULL)
result <- takeSingletons(result, shinysession$singletons, desingleton=FALSE)$ui
result <- surroundSingletons(result)
dependencies <- lapply(resolveDependencies(findDependencies(result)),
createWebDependency)
names(dependencies) <- NULL
# renderTags returns a list with head, singletons, and html
output <- list(
html = doRenderTags(result),
deps = dependencies
)
return(output)
})
}
#' File Downloads
#'
#' Allows content from the Shiny application to be made available to the user as
#' file downloads (for example, downloading the currently visible data as a CSV
#' file). Both filename and contents can be calculated dynamically at the time
#' the user initiates the download. Assign the return value to a slot on
#' \code{output} in your server function, and in the UI use
#' \code{\link{downloadButton}} or \code{\link{downloadLink}} to make the
#' download available.
#'
#' @param filename A string of the filename, including extension, that the
#' user's web browser should default to when downloading the file; or a
#' function that returns such a string. (Reactive values and functions may be
#' used from this function.)
#' @param content A function that takes a single argument \code{file} that is a
#' file path (string) of a nonexistent temp file, and writes the content to
#' that file path. (Reactive values and functions may be used from this
#' function.)
#' @param contentType A string of the download's
#' \href{http://en.wikipedia.org/wiki/Internet_media_type}{content type}, for
#' example \code{"text/csv"} or \code{"image/png"}. If \code{NULL} or
#' \code{NA}, the content type will be guessed based on the filename
#' extension, or \code{application/octet-stream} if the extension is unknown.
#'
#' @examples
#' \dontrun{
#' # In server.R:
#' output$downloadData <- downloadHandler(
#' filename = function() {
#' paste('data-', Sys.Date(), '.csv', sep='')
#' },
#' content = function(file) {
#' write.csv(data, file)
#' }
#' )
#'
#' # In ui.R:
#' downloadLink('downloadData', 'Download')
#' }
#'
#' @export
downloadHandler <- function(filename, content, contentType=NA) {
return(markRenderFunction(downloadButton, function(shinysession, name, ...) {
shinysession$registerDownload(name, filename, contentType, content)
}))
}
#' Table output with the JavaScript library DataTables
#'
#' Makes a reactive version of the given function that returns a data frame (or
#' matrix), which will be rendered with the DataTables library. Paging,
#' searching, filtering, and sorting can be done on the R side using Shiny as
#' the server infrastructure.
#'
#' For the \code{options} argument, the character elements that have the class
#' \code{"AsIs"} (usually returned from \code{\link{I}()}) will be evaluated in
#' JavaScript. This is useful when the type of the option value is not supported
#' in JSON, e.g., a JavaScript function, which can be obtained by evaluating a
#' character string.
#' @param expr An expression that returns a data frame or a matrix.
#' @param options A list of initialization options to be passed to DataTables,
#' or a function to return such a list.
#' @param searchDelay The delay for searching, in milliseconds (to avoid too
#' frequent search requests).
#' @param callback A JavaScript function to be applied to the DataTable object.
#' This is useful for DataTables plug-ins, which often require the DataTable
#' instance to be available (\url{http://datatables.net/extras/}).
#' @references \url{http://datatables.net}
#' @export
#' @inheritParams renderPlot
#' @examples # pass a callback function to DataTables using I()
#' renderDataTable(iris,
#' options = list(
#' iDisplayLength = 5,
#' fnInitComplete = I("function(oSettings, json) {alert('Done.');}")
#' )
#' )
renderDataTable <- function(expr, options = NULL, searchDelay = 500,
callback = 'function(oTable) {}',
env = parent.frame(), quoted = FALSE) {
installExprFunction(expr, "func", env, quoted)
markRenderFunction(dataTableOutput, function(shinysession, name, ...) {
res <- checkAsIs(if (is.function(options)) options() else options)
data <- func()
if (length(dim(data)) != 2) return() # expects a rectangular data object
action <- shinysession$registerDataObj(name, data, dataTablesJSON)
list(
colnames = colnames(data), action = action, options = res$options,
evalOptions = if (length(res$eval)) I(res$eval), searchDelay = searchDelay,
callback = paste(callback, collapse = '\n')
)
})
}
# Deprecated functions ------------------------------------------------------
#' Plot output (deprecated)
#'
#' See \code{\link{renderPlot}}.
#' @param func A function.
#' @param width Width.
#' @param height Height.
#' @param ... Other arguments to pass on.
#' @export
reactivePlot <- function(func, width='auto', height='auto', ...) {
shinyDeprecated(new="renderPlot")
renderPlot({ func() }, width=width, height=height, ...)
}
#' Table output (deprecated)
#'
#' See \code{\link{renderTable}}.
#' @param func A function.
#' @param ... Other arguments to pass on.
#' @export
reactiveTable <- function(func, ...) {
shinyDeprecated(new="renderTable")
renderTable({ func() })
}
#' Print output (deprecated)
#'
#' See \code{\link{renderPrint}}.
#' @param func A function.
#' @export
reactivePrint <- function(func) {
shinyDeprecated(new="renderPrint")
renderPrint({ func() })
}
#' UI output (deprecated)
#'
#' See \code{\link{renderUI}}.
#' @param func A function.
#' @export
reactiveUI <- function(func) {
shinyDeprecated(new="renderUI")
renderUI({ func() })
}
#' Text output (deprecated)
#'
#' See \code{\link{renderText}}.
#' @param func A function.
#' @export
reactiveText <- function(func) {
shinyDeprecated(new="renderText")
renderText({ func() })
}

162
R/showcase.R Normal file
View File

@@ -0,0 +1,162 @@
#' @include globals.R
NULL
# Given the name of a license, return the appropriate link HTML for the
# license, which may just be the name of the license if the name is
# unrecognized.
#
# Recognizes the 'standard' set of licenses used for R packages
# (see http://cran.r-project.org/doc/manuals/R-exts.html)
licenseLink <- function(licenseName) {
licenses <- list(
"GPL-2" = "https://gnu.org/licenses/gpl-2.0.txt",
"GPL-3" = "https://gnu.org/licenses/gpl-3.0.txt",
"LGPL-3" = "https://www.gnu.org/licenses/lgpl-3.0.txt",
"LGPL-2" = "http://www.gnu.org/licenses/old-licenses/lgpl-2.0.txt",
"LGPL-2.1" = "http://www.gnu.org/licenses/lgpl-2.1.txt",
"AGPL-3" = "http://www.gnu.org/licenses/agpl-3.0.txt",
"Artistic-2.0" = "http://www.r-project.org/Licenses/Artistic-2.0",
"BSD_2_clause" = "http://www.r-project.org/Licenses/BSD_2_clause",
"BSD_3_clause" = "http://www.r-project.org/Licenses/BSD_3_clause",
"MIT" = "http://www.r-project.org/Licenses/MIT")
if (exists(licenseName, where = licenses)) {
tags$a(href=licenses[[licenseName]], licenseName)
} else {
licenseName
}
}
# Returns tags containing showcase directives intended for the <HEAD> of the
# document.
showcaseHead <- function() {
deps <- list(
htmlDependency("jqueryui", "1.10.4", c(href="shared/jqueryui/1.10.4"),
script = "jquery-ui.min.js"),
htmlDependency("showdown", "0.3.1", c(href="shared/showdown/compressed"),
script = "showdown.js"),
htmlDependency("font-awesome", "4.0.3", c(href="shared/font-awesome"),
stylesheet = "css/font-awesome.min.css"),
htmlDependency("highlight.js", "6.2", c(href="shared/highlight"),
script = "highlight.pack.js")
)
mdfile <- file.path.ci(getwd(), 'Readme.md')
html <- with(tags, tagList(
script(src="shared/shiny-showcase.js"),
link(rel="stylesheet", type="text/css",
href="shared/highlight/rstudio.css"),
link(rel="stylesheet", type="text/css",
href="shared/shiny-showcase.css"),
if (file.exists(mdfile))
script(type="text/markdown", id="showcase-markdown-content",
paste(readLines(mdfile, warn = FALSE), collapse="\n"))
else ""
))
return(attachDependencies(html, deps))
}
# Returns tags containing the application metadata (title and author) in
# showcase mode.
appMetadata <- function(desc) {
cols <- colnames(desc)
if ("Title" %in% cols)
with(tags, h4(class="muted shiny-showcase-apptitle", desc[1,"Title"],
if ("Author" %in% cols) small(
br(), "by",
if ("AuthorUrl" %in% cols)
a(href=desc[1,"AuthorUrl"], class="shiny-showcase-appauthor",
desc[1,"Author"])
else
desc[1,"Author"],
if ("AuthorEmail" %in% cols)
a(href=paste("mailto:", desc[1,"AuthorEmail"], sep = ''),
class="shiny-showcase-appauthoreemail",
desc[1,"AuthorEmail"])
else "")
else ""))
else ""
}
# Returns tags containing the application's code in Bootstrap-style tabs in
# showcase mode.
showcaseCodeTabs <- function(codeLicense) {
rFiles <- list.files(pattern = "\\.[rR]$")
with(tags, div(id="showcase-code-tabs",
a(id="showcase-code-position-toggle",
class="btn btn-default btn-small",
onclick="toggleCodePosition()",
i(class="fa fa-level-up", "show with app")),
ul(class="nav nav-tabs",
lapply(rFiles, function(rFile) {
li(class=if (tolower(rFile) == "server.r") "active" else "",
a(href=paste("#", gsub(".", "_", rFile, fixed=TRUE),
"_code", sep=""),
"data-toggle"="tab", rFile))
})),
div(class="tab-content", id="showcase-code-content",
lapply(rFiles, function(rFile) {
div(class=paste("tab-pane",
if (tolower(rFile) == "server.r") " active" else "",
sep=""),
id=paste(gsub(".", "_", rFile, fixed=TRUE),
"_code", sep=""),
pre(class="shiny-code",
# we need to prevent the indentation of <code> ... </code>
HTML(format(tags$code(
class="language-r",
paste(readLines(file.path.ci(getwd(), rFile), warn=FALSE),
collapse="\n")
), indent = FALSE))))
})),
codeLicense))
}
# Returns tags containing the showcase application information (readme and
# code).
showcaseAppInfo <- function() {
descfile <- file.path.ci(getwd(), "DESCRIPTION")
hasDesc <- file.exists(descfile)
readmemd <- file.path.ci(getwd(), "Readme.md")
hasReadme <- file.exists(readmemd)
if (hasDesc) {
desc <- read.dcf(descfile)
}
with(tags,
div(class="container-fluid shiny-code-container well",
id="showcase-well",
div(class="row-fluid",
if (hasDesc || hasReadme) {
div(id="showcase-app-metadata", class="span4",
if (hasDesc) appMetadata(desc) else "",
if (hasReadme) div(id="readme-md"))
} else "",
div(id="showcase-code-inline",
class=if (hasReadme || hasDesc) "span8" else "span10 offset1",
showcaseCodeTabs(
if (hasDesc && "License" %in% colnames(desc)) {
small(class="showcase-code-license muted",
"Code license: ",
licenseLink(desc[1,"License"]))
} else "")))))
}
# Returns the body of the showcase document, given the HTML it should wrap.
showcaseBody <- function(htmlBody) {
with(tags, tagList(
table(id="showcase-app-code",
tr(td(id="showcase-app-container",
class="showcase-app-container-expanded",
HTML(htmlBody),
td(id="showcase-sxs-code",
class="showcase-sxs-code-collapsed")))),
showcaseAppInfo()))
}
# Sets the defaults for showcase mode (for app boot).
setShowcaseDefault <- function(showcaseDefault) {
.globals$showcaseDefault <- showcaseDefault
.globals$showcaseOverride <- as.logical(showcaseDefault)
}

142
R/slider.R Normal file
View File

@@ -0,0 +1,142 @@
hasDecimals <- function(value) {
truncatedValue <- round(value)
return (!identical(value, truncatedValue))
}
#' @rdname sliderInput
#'
#' @param interval The interval, in milliseconds, between each animation step.
#' @param loop \code{TRUE} to automatically restart the animation when it
#' reaches the end.
#' @param playButton Specifies the appearance of the play button. Valid values
#' are a one-element character vector (for a simple text label), an HTML tag
#' or list of tags (using \code{\link{tag}} and friends), or raw HTML (using
#' \code{\link{HTML}}).
#' @param pauseButton Similar to \code{playButton}, but for the pause button.
#'
#' @export
animationOptions <- function(interval=1000,
loop=FALSE,
playButton=NULL,
pauseButton=NULL) {
list(interval=interval,
loop=loop,
playButton=playButton,
pauseButton=pauseButton)
}
# Create a new slider control (list of slider input element and the script
# tag used to configure it). This is a lower level control that should
# be wrapped in an "input" construct (e.g. sliderInput in bootstrap.R)
#
# this is a wrapper for: https://github.com/egorkhmelev/jslider
# (www/shared/slider contains js, css, and img dependencies)
slider <- function(inputId, min, max, value, step = NULL, ...,
round=FALSE, format='#,##0.#####', locale='us',
ticks=TRUE, animate=FALSE, width=NULL) {
# validate inputId
inputId <- as.character(inputId)
if (!is.character(inputId))
stop("inputId not specified")
# validate numeric inputs
if (!is.numeric(value) || !is.numeric(min) || !is.numeric(max))
stop("min, max, and value must all be numeric values")
else if (min(value) < min)
stop(paste("slider initial value", value,
"is less than the specified minimum"))
else if (max(value) > max)
stop(paste("slider initial value", value,
"is greater than the specified maximum"))
else if (min > max)
stop(paste("slider maximum is greater than minimum"))
else if (!is.null(step)) {
if (!is.numeric(step))
stop("step is not a numeric value")
if (step > (max - min))
stop("step is greater than range")
}
# step
range <- max - min
if (is.null(step)) {
# short range or decimals means continuous decimal
if (range < 2 || hasDecimals(min) || hasDecimals(max))
step <- range / 250 # ~ one step per pixel
else
step = 1
}
# Default state is to not have ticks
if (identical(ticks, TRUE)) {
# Automatic ticks
tickCount <- (range / step) + 1
if (tickCount <= 26)
ticks <- paste(rep('|', floor(tickCount)), collapse=';')
else {
ticks <- NULL
# # This is a smarter auto-tick algorithm, but to be truly useful
# # we need jslider to be able to space ticks irregularly
# tickSize <- 10^(floor(log10(range/0.39)))
# if ((range / tickSize) == floor(range / tickSize)) {
# ticks <- paste(rep('|', (range / tickSize) + 1), collapse=';')
# }
# else {
# ticks <- NULL
# }
}
}
else if (is.numeric(ticks) && length(ticks) == 1) {
# Use n ticks
ticks <- paste(rep('|', ticks), collapse=';')
}
else if (length(ticks) > 1 && (is.numeric(ticks) || is.character(ticks))) {
# Explicit ticks
ticks <- paste(ticks, collapse=';')
}
else {
ticks <- NULL
}
# build slider
dep <- htmlDependency("jslider", "1", c(href="shared/slider"),
script = "js/jquery.slider.min.js",
stylesheet = "css/jquery.slider.min.css"
)
sliderFragment <- list(
attachDependencies(
tags$input(
id=inputId, type="slider",
name=inputId, value=paste(value, collapse=';'), class="jslider",
'data-from'=min, 'data-to'=max, 'data-step'=step,
'data-skin'='plastic', 'data-round'=round, 'data-locale'=locale,
'data-format'=format, 'data-scale'=ticks,
'data-smooth'=FALSE,
'data-width'=validateCssUnit(width)
),
dep
)
)
if (identical(animate, TRUE))
animate <- animationOptions()
if (!is.null(animate) && !identical(animate, FALSE)) {
if (is.null(animate$playButton))
animate$playButton <- 'Play'
if (is.null(animate$pauseButton))
animate$pauseButton <- 'Pause'
sliderFragment[[length(sliderFragment)+1]] <-
tags$div(class='slider-animate-container',
tags$a(href='#',
class='slider-animate-button',
'data-target-id'=inputId,
'data-interval'=animate$interval,
'data-loop'=animate$loop,
tags$span(class='play', animate$playButton),
tags$span(class='pause', animate$pauseButton)))
}
return(tagList(sliderFragment))
}

191
R/tar.R Normal file
View File

@@ -0,0 +1,191 @@
# This file was pulled from the R code base as of
# Thursday, November 22, 2012 at 6:24:55 AM UTC
# and edited to remove everything but the copyright
# header and untar2, and to make untar2 more tolerant
# of the 'x' and 'g' extended block indicators, the
# latter of which is used in tar files generated by
# GitHub.
# File src/library/utils/R/tar.R
# Part of the R package, http://www.R-project.org
#
# Copyright (C) 1995-2012 The R Core Team
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# A copy of the GNU General Public License is available at
# http://www.r-project.org/Licenses/
untar2 <- function(tarfile, files = NULL, list = FALSE, exdir = ".")
{
getOct <- function(x, offset, len)
{
x <- 0L
for(i in offset + seq_len(len)) {
z <- block[i]
if(!as.integer(z)) break; # terminate on nul
switch(rawToChar(z),
" " = {},
"0"=,"1"=,"2"=,"3"=,"4"=,"5"=,"6"=,"7"=
{x <- 8*x + (as.integer(z)-48)},
stop("invalid octal digit")
)
}
x
}
mydir.create <- function(path, ...) {
## for Windows' sake
path <- sub("[\\/]$", "", path)
if(file_test("-d", path)) return()
if(!dir.create(path, showWarnings = TRUE, recursive = TRUE, ...))
stop(gettextf("failed to create directory %s", sQuote(path)),
domain = NA)
}
warn1 <- character()
## A tar file is a set of 512 byte records,
## a header record followed by file contents (zero-padded).
## See http://en.wikipedia.org/wiki/Tar_%28file_format%29
if(is.character(tarfile) && length(tarfile) == 1L) {
con <- gzfile(path.expand(tarfile), "rb") # reads compressed formats
on.exit(close(con))
} else if(inherits(tarfile, "connection")) con <- tarfile
else stop("'tarfile' must be a character string or a connection")
if (!missing(exdir)) {
mydir.create(exdir)
od <- setwd(exdir)
on.exit(setwd(od), add = TRUE)
}
contents <- character()
llink <- lname <- NULL
repeat{
block <- readBin(con, "raw", n = 512L)
if(!length(block)) break
if(length(block) < 512L) stop("incomplete block on file")
if(all(block == 0)) break
ns <- max(which(block[1:100] > 0))
name <- rawToChar(block[seq_len(ns)])
magic <- rawToChar(block[258:262])
if ((magic == "ustar") && block[346] > 0) {
ns <- max(which(block[346:500] > 0))
prefix <- rawToChar(block[345+seq_len(ns)])
name <- file.path(prefix, name)
}
## mode zero-padded 8 bytes (including nul) at 101
## Aargh: bsdtar has this one incorrectly with 6 bytes+space
mode <- as.octmode(getOct(block, 100, 8))
size <- getOct(block, 124, 12)
ts <- getOct(block, 136, 12)
ft <- as.POSIXct(as.numeric(ts), origin="1970-01-01", tz="UTC")
csum <- getOct(block, 148, 8)
block[149:156] <- charToRaw(" ")
xx <- as.integer(block)
checksum <- sum(xx) %% 2^24 # 6 bytes
if(csum != checksum) {
## try it with signed bytes.
checksum <- sum(ifelse(xx > 127, xx - 128, xx)) %% 2^24 # 6 bytes
if(csum != checksum)
warning(gettextf("checksum error for entry '%s'", name),
domain = NA)
}
type <- block[157L]
ctype <- rawToChar(type)
if(type == 0L || ctype == "0") {
if(!is.null(lname)) {name <- lname; lname <- NULL}
contents <- c(contents, name)
remain <- size
dothis <- !list
if(dothis && length(files)) dothis <- name %in% files
if(dothis) {
mydir.create(dirname(name))
out <- file(name, "wb")
}
for(i in seq_len(ceiling(size/512L))) {
block <- readBin(con, "raw", n = 512L)
if(length(block) < 512L)
stop("incomplete block on file")
if (dothis) {
writeBin(block[seq_len(min(512L, remain))], out)
remain <- remain - 512L
}
}
if(dothis) {
close(out)
Sys.chmod(name, mode, FALSE) # override umask
Sys.setFileTime(name, ft)
}
} else if(ctype %in% c("1", "2")) { # hard and symbolic links
contents <- c(contents, name)
ns <- max(which(block[158:257] > 0))
name2 <- rawToChar(block[157L + seq_len(ns)])
if(!is.null(lname)) {name <- lname; lname <- NULL}
if(!is.null(llink)) {name2 <- llink; llink <- NULL}
if(!list) {
if(ctype == "1") {
if (!file.link(name2, name)) { # will give a warning
## link failed, so try a file copy
if(file.copy(name2, name))
warn1 <- c(warn1, "restoring hard link as a file copy")
else
warning(gettextf("failed to copy %s to %s", sQuote(name2), sQuote(name)), domain = NA)
}
} else {
if(.Platform$OS.type == "windows") {
## this will not work for links to dirs
from <- file.path(dirname(name), name2)
if (!file.copy(from, name))
warning(gettextf("failed to copy %s to %s", sQuote(from), sQuote(name)), domain = NA)
else
warn1 <- c(warn1, "restoring symbolic link as a file copy")
} else {
if(!file.symlink(name2, name)) { # will give a warning
## so try a file copy: will not work for links to dirs
from <- file.path(dirname(name), name2)
if (file.copy(from, name))
warn1 <- c(warn1, "restoring symbolic link as a file copy")
else
warning(gettextf("failed to copy %s to %s", sQuote(from), sQuote(name)), domain = NA)
}
}
}
}
} else if(ctype == "5") {
contents <- c(contents, name)
if(!list) {
mydir.create(name)
Sys.chmod(name, mode, TRUE) # FIXME: check result
## no point is setting time, as dir will be populated later.
}
} else if(ctype %in% c("L", "K")) {
## This is a GNU extension that should no longer be
## in use, but it is.
name_size <- 512L * ceiling(size/512L)
block <- readBin(con, "raw", n = name_size)
if(length(block) < name_size)
stop("incomplete block on file")
ns <- max(which(block > 0)) # size on file may or may not include final nul
if(ctype == "L")
lname <- rawToChar(block[seq_len(ns)])
else
llink <- rawToChar(block[seq_len(ns)])
} else if(ctype %in% c("x", "g")) {
readBin(con, "raw", n = 512L*ceiling(size/512L))
} else stop("unsupported entry type ", sQuote(ctype))
}
if(length(warn1)) {
warn1 <- unique(warn1)
for (w in warn1) warning(w, domain = NA)
}
if(list) contents else invisible(0L)
}

72
R/timer.R Normal file
View File

@@ -0,0 +1,72 @@
# Return the current time, in milliseconds from epoch, with
# unspecified time zone.
now <- function() {
as.numeric(Sys.time()) * 1000
}
TimerCallbacks <- setRefClass(
'TimerCallbacks',
fields = list(
.nextId = 'integer',
.funcs = 'Map',
.times = 'data.frame'
),
methods = list(
initialize = function() {
.nextId <<- 0L
},
clear = function() {
.nextId <<- 0L
.funcs$clear()
.times <<- data.frame()
},
schedule = function(millis, func) {
id <- .nextId
.nextId <<- .nextId + 1L
t <- now()
# TODO: Horribly inefficient, use a heap instead
.times <<- rbind(.times, data.frame(time=t+millis,
scheduled=t,
id=id))
.times <<- .times[order(.times$time),]
.funcs$set(as.character(id), func)
return(id)
},
timeToNextEvent = function() {
if (dim(.times)[1] == 0)
return(Inf)
return(.times[1, 'time'] - now())
},
takeElapsed = function() {
t <- now()
elapsed <- .times$time < now()
result <- .times[elapsed,]
.times <<- .times[!elapsed,]
# TODO: Examine scheduled column to check if any funny business
# has occurred with the system clock (e.g. if scheduled
# is later than now())
return(result)
},
executeElapsed = function() {
elapsed <- takeElapsed()
if (length(elapsed) == 0)
return(FALSE)
for (id in elapsed$id) {
thisFunc <- .funcs$remove(as.character(id))
# TODO: Catch exception, and...?
# TODO: Detect NULL, and...?
thisFunc()
}
return(TRUE)
}
)
)
timerCallbacks <- TimerCallbacks$new()

466
R/update-input.R Normal file
View File

@@ -0,0 +1,466 @@
#' Change the value of a text input on the client
#'
#' @template update-input
#' @param value The value to set for the input object.
#'
#' @seealso \code{\link{textInput}}
#'
#' @examples
#' \dontrun{
#' shinyServer(function(input, output, session) {
#'
#' observe({
#' # We'll use the input$controller variable multiple times, so save it as x
#' # for convenience.
#' x <- input$controller
#'
#' # This will change the value of input$inText, based on x
#' updateTextInput(session, "inText", value = paste("New text", x))
#'
#' # Can also set the label, this time for input$inText2
#' updateTextInput(session, "inText2",
#' label = paste("New label", x),
#' value = paste("New text", x))
#' })
#' })
#' }
#' @export
updateTextInput <- function(session, inputId, label = NULL, value = NULL) {
message <- dropNulls(list(label=label, value=value))
session$sendInputMessage(inputId, message)
}
#' Change the value of a checkbox input on the client
#'
#' @template update-input
#' @param value The value to set for the input object.
#'
#' @seealso \code{\link{checkboxInput}}
#'
#' @examples
#' \dontrun{
#' shinyServer(function(input, output, session) {
#'
#' observe({
#' # TRUE if input$controller is even, FALSE otherwise.
#' x_even <- input$controller %% 2 == 0
#'
#' updateCheckboxInput(session, "inCheckbox", value = x_even)
#' })
#' })
#' }
#' @export
updateCheckboxInput <- updateTextInput
#' Change the value of a slider input on the client
#'
#' @template update-input
#' @param value The value to set for the input object.
#'
#' @seealso \code{\link{sliderInput}}
#'
#' @examples
#' \dontrun{
#' shinyServer(function(input, output, session) {
#'
#' observe({
#' # We'll use the input$controller variable multiple times, so save it as x
#' # for convenience.
#' x <- input$controller
#'
#' # Similar to number and text. only label and value can be set for slider
#' updateSliderInput(session, "inSlider",
#' label = paste("Slider label", x),
#' value = x)
#'
#' # For sliders that pick out a range, pass in a vector of 2 values.
#' updateSliderInput(session, "inSlider2", value = c(x-1, x+1))
#'
#' # An NA means to not change that value (the low or high one)
#' updateSliderInput(session, "inSlider3", value = c(NA, x+2))
#' })
#' })
#' }
#' @export
updateSliderInput <- updateTextInput
#' Change the value of a date input on the client
#'
#' @template update-input
#' @param value The desired date value. Either a Date object, or a string in
#' \code{yyyy-mm-dd} format.
#' @param min The minimum allowed date. Either a Date object, or a string in
#' \code{yyyy-mm-dd} format.
#' @param max The maximum allowed date. Either a Date object, or a string in
#' \code{yyyy-mm-dd} format.
#'
#' @seealso \code{\link{dateInput}}
#'
#' @examples
#' \dontrun{
#' shinyServer(function(input, output, session) {
#'
#' observe({
#' # We'll use the input$controller variable multiple times, so save it as x
#' # for convenience.
#' x <- input$controller
#'
#' updateDateInput(session, "inDate",
#' label = paste("Date label", x),
#' value = paste("2013-04-", x, sep=""),
#' min = paste("2013-04-", x-1, sep=""),
#' max = paste("2013-04-", x+1, sep="")
#' )
#' })
#' })
#' }
#' @export
updateDateInput <- function(session, inputId, label = NULL, value = NULL,
min = NULL, max = NULL) {
# If value is a date object, convert it to a string with yyyy-mm-dd format
# Same for min and max
if (inherits(value, "Date")) value <- format(value, "%Y-%m-%d")
if (inherits(min, "Date")) min <- format(min, "%Y-%m-%d")
if (inherits(max, "Date")) max <- format(max, "%Y-%m-%d")
message <- dropNulls(list(label=label, value=value, min=min, max=max))
session$sendInputMessage(inputId, message)
}
#' Change the start and end values of a date range input on the client
#'
#' @template update-input
#' @param start The start date. Either a Date object, or a string in
#' \code{yyyy-mm-dd} format.
#' @param end The end date. Either a Date object, or a string in
#' \code{yyyy-mm-dd} format.
#' @param min The minimum allowed date. Either a Date object, or a string in
#' \code{yyyy-mm-dd} format.
#' @param max The maximum allowed date. Either a Date object, or a string in
#' \code{yyyy-mm-dd} format.
#'
#' @seealso \code{\link{dateRangeInput}}
#'
#' @examples
#' \dontrun{
#' shinyServer(function(input, output, session) {
#'
#' observe({
#' # We'll use the input$controller variable multiple times, so save it as x
#' # for convenience.
#' x <- input$controller
#'
#' updateDateRangeInput(session, "inDateRange",
#' label = paste("Date range label", x),
#' start = paste("2013-01-", x, sep=""))
#' end = paste("2013-12-", x, sep=""))
#' })
#' })
#' }
#' @export
updateDateRangeInput <- function(session, inputId, label = NULL,
start = NULL, end = NULL, min = NULL, max = NULL) {
# Make sure start and end are strings, not date objects. This is for
# consistency across different locales.
if (inherits(start, "Date")) start <- format(start, '%Y-%m-%d')
if (inherits(end, "Date")) end <- format(end, '%Y-%m-%d')
if (inherits(min, "Date")) min <- format(min, '%Y-%m-%d')
if (inherits(max, "Date")) max <- format(max, '%Y-%m-%d')
message <- dropNulls(list(
label = label,
value = c(start, end),
min = min,
max = max
))
session$sendInputMessage(inputId, message)
}
#' Change the selected tab on the client
#'
#' @param session The \code{session} object passed to function given to
#' \code{shinyServer}.
#' @param inputId The id of the \code{tabsetPanel}, \code{navlistPanel},
#' or \code{navbarPage} object.
#' @param selected The name of the tab to make active.
#'
#' @seealso \code{\link{tabsetPanel}}, \code{\link{navlistPanel}},
#' \code{\link{navbarPage}}
#'
#' @examples
#' \dontrun{
#' shinyServer(function(input, output, session) {
#'
#' observe({
#' # TRUE if input$controller is even, FALSE otherwise.
#' x_even <- input$controller %% 2 == 0
#'
#' # Change the selected tab.
#' # Note that the tabset container must have been created with an 'id' argument
#' if (x_even) {
#' updateTabsetPanel(session, "inTabset", selected = "panel2")
#' } else {
#' updateTabsetPanel(session, "inTabset", selected = "panel1")
#' }
#' })
#' })
#' }
#' @export
updateTabsetPanel <- function(session, inputId, selected = NULL) {
message <- dropNulls(list(value = selected))
session$sendInputMessage(inputId, message)
}
#' Change the value of a number input on the client
#'
#' @template update-input
#' @param value The value to set for the input object.
#' @param min Minimum value.
#' @param max Maximum value.
#' @param step Step size.
#'
#' @seealso \code{\link{numericInput}}
#'
#' @examples
#' \dontrun{
#' shinyServer(function(input, output, session) {
#'
#' observe({
#' # We'll use the input$controller variable multiple times, so save it as x
#' # for convenience.
#' x <- input$controller
#'
#' updateNumericInput(session, "inNumber", value = x)
#'
#' updateNumericInput(session, "inNumber2",
#' label = paste("Number label ", x),
#' value = x, min = x-10, max = x+10, step = 5)
#' })
#' })
#' }
#' @export
updateNumericInput <- function(session, inputId, label = NULL, value = NULL,
min = NULL, max = NULL, step = NULL) {
message <- dropNulls(list(
label = label, value = formatNoSci(value),
min = formatNoSci(min), max = formatNoSci(max), step = formatNoSci(step)
))
session$sendInputMessage(inputId, message)
}
#' Change the value of a checkbox group input on the client
#'
#' @template update-input
#' @param choices A named vector or named list of options. For each item, the
#' name will be used as the label, and the value will be used as the value.
#' @param selected A vector or list of options (values) which will be selected.
#'
#' @seealso \code{\link{checkboxGroupInput}}
#'
#' @examples
#' \dontrun{
#' shinyServer(function(input, output, session) {
#'
#' observe({
#' # We'll use the input$controller variable multiple times, so save it as x
#' # for convenience.
#' x <- input$controller
#'
#' # Create a list of new options, where the name of the items is something
#' # like 'option label x 1', and the values are 'option-x-1'.
#' cb_options <- list()
#' cb_options[[sprintf("option label %d 1", x)]] <- sprintf("option-%d-1", x)
#' cb_options[[sprintf("option label %d 2", x)]] <- sprintf("option-%d-2", x)
#'
#' # Change values for input$inCheckboxGroup
#' updateCheckboxGroupInput(session, "inCheckboxGroup", choices = cb_options)
#'
#' # Can also set the label and select items
#' updateCheckboxGroupInput(session, "inCheckboxGroup2",
#' label = paste("checkboxgroup label", x),
#' choices = cb_options,
#' selected = sprintf("option-%d-2", x)
#' )
#' })
#' })
#' }
#' @export
updateCheckboxGroupInput <- function(session, inputId, label = NULL,
choices = NULL, selected = NULL) {
choices <- choicesWithNames(choices)
if (!is.null(selected))
selected <- validateSelected(selected, choices, inputId)
options <- if (length(choices))
columnToRowData(list(value = choices, label = names(choices)))
message <- dropNulls(list(label = label, options = options, value = selected))
session$sendInputMessage(inputId, message)
}
#' Change the value of a radio input on the client
#'
#' @template update-input
#' @param choices A named vector or named list of options. For each item, the
#' name will be used as the label, and the value will be used as the value.
#' @param selected A vector or list of options (values) which will be selected.
#'
#' @seealso \code{\link{radioButtons}}
#'
#' @examples
#' \dontrun{
#' shinyServer(function(input, output, session) {
#'
#' observe({
#' # We'll use the input$controller variable multiple times, so save it as x
#' # for convenience.
#' x <- input$controller
#'
#' r_options <- list()
#' r_options[[sprintf("option label %d 1", x)]] <- sprintf("option-%d-1", x)
#' r_options[[sprintf("option label %d 2", x)]] <- sprintf("option-%d-2", x)
#'
#' # Change values for input$inRadio
#' updateRadioButtons(session, "inRadio", choices = r_options)
#'
#' # Can also set the label and select an item
#' updateRadioButtons(session, "inRadio2",
#' label = paste("Radio label", x),
#' choices = r_options,
#' selected = sprintf("option-%d-2", x)
#' )
#' })
#' })
#' }
#' @export
updateRadioButtons <- updateCheckboxGroupInput
#' Change the value of a select input on the client
#'
#' @template update-input
#' @param choices A named vector or named list of options. For each item, the
#' name will be used as the label, and the value will be used as the value.
#' @param selected A vector or list of options (values) which will be selected.
#'
#' @seealso \code{\link{selectInput}}
#'
#' @examples
#' \dontrun{
#' shinyServer(function(input, output, session) {
#'
#' observe({
#' # We'll use the input$controller variable multiple times, so save it as x
#' # for convenience.
#' x <- input$controller
#'
#' # Create a list of new options, where the name of the items is something
#' # like 'option label x 1', and the values are 'option-x-1'.
#' s_options <- list()
#' s_options[[sprintf("option label %d 1", x)]] <- sprintf("option-%d-1", x)
#' s_options[[sprintf("option label %d 2", x)]] <- sprintf("option-%d-2", x)
#'
#' # Change values for input$inSelect
#' updateSelectInput(session, "inSelect", choices = s_options)
#'
#' # Can also set the label and select an item (or more than one if it's a
#' # multi-select)
#' updateSelectInput(session, "inSelect2",
#' label = paste("Select label", x),
#' choices = s_options,
#' selected = sprintf("option-%d-2", x)
#' )
#' })
#' })
#' }
#' @export
updateSelectInput <- updateCheckboxGroupInput
#' @rdname updateSelectInput
#' @param options a list of options (see \code{\link{selectizeInput}})
#' @param server whether to store \code{choices} on the server side, and load
#' the select options dynamically on searching, instead of writing all
#' \code{choices} into the page at once (i.e., only use the client-side
#' version of \pkg{selectize.js})
#' @export
updateSelectizeInput <- function(
session, inputId, label = NULL, choices = NULL, selected = NULL,
options = list(), server = FALSE
) {
if (length(options)) {
res <- checkAsIs(options)
cfg <- tags$script(
type = 'application/json',
`data-for` = inputId,
`data-eval` = if (length(res$eval)) HTML(toJSON(res$eval)),
HTML(toJSON(res$options))
)
session$sendInputMessage(inputId, list(newOptions = as.character(cfg)))
}
if (!server) {
return(updateSelectInput(session, inputId, label, choices, selected))
}
# in the server mode, the choices are not available before we type, so we
# cannot really pre-select any options, but here we insert the `selected`
# options into selectize forcibly
value <- unname(selected)
selected <- choicesWithNames(selected)
message <- dropNulls(list(
label = label,
value = value,
selected = if (length(selected)) {
columnToRowData(list(label = names(selected), value = selected))
},
url = session$registerDataObj(inputId, choices, selectizeJSON)
))
session$sendInputMessage(inputId, message)
}
selectizeJSON <- function(data, req) {
query <- parseQueryString(req$QUERY_STRING)
# extract the query variables, conjunction (and/or), search string, maximum options
var <- fromJSON(query$field)
cjn <- if (query$conju == 'and') all else any
# all keywords in lower-case, for case-insensitive matching
key <- unique(strsplit(tolower(query$query), '\\s+')[[1]])
if (identical(key, '')) key <- character(0)
mop <- query$maxop
# convert a single vector to a data frame so it returns {label: , value: }
# later in JSON; other objects return arbitrary JSON {x: , y: , foo: , ...}
data <- if (is.atomic(data)) {
data <- choicesWithNames(data)
data.frame(label = names(data), value = data, stringsAsFactors = FALSE)
} else as.data.frame(data, stringsAsFactors = FALSE)
# start searching for keywords in all specified columns
idx <- logical(nrow(data))
if (length(key)) for (v in var) {
matches <- do.call(
cbind,
lapply(key, function(k) {
grepl(k, tolower(as.character(data[[v]])), fixed = TRUE)
})
)
# merge column matches using OR, and match multiple keywords in one column
# using the conjunction setting (AND or OR)
idx <- idx | apply(matches, 1, cjn)
}
# only return the first n rows (n = maximum options in configuration)
idx <- head(which(idx), mop)
data <- data[idx, ]
httpResponse(200, 'application/json', toJSON(columnToRowData(data)))
}

899
R/utils.R Normal file
View File

@@ -0,0 +1,899 @@
#' @include globals.R
#' @include map.R
NULL
#' Make a random number generator repeatable
#'
#' Given a function that generates random data, returns a wrapped version of
#' that function that always uses the same seed when called. The seed to use can
#' be passed in explicitly if desired; otherwise, a random number is used.
#'
#' @param rngfunc The function that is affected by the R session's seed.
#' @param seed The seed to set every time the resulting function is called.
#' @return A repeatable version of the function that was passed in.
#'
#' @note When called, the returned function attempts to preserve the R session's
#' current seed by snapshotting and restoring
#' \code{\link[base]{.Random.seed}}.
#'
#' @examples
#' rnormA <- repeatable(rnorm)
#' rnormB <- repeatable(rnorm)
#' rnormA(3) # [1] 1.8285879 -0.7468041 -0.4639111
#' rnormA(3) # [1] 1.8285879 -0.7468041 -0.4639111
#' rnormA(5) # [1] 1.8285879 -0.7468041 -0.4639111 -1.6510126 -1.4686924
#' rnormB(5) # [1] -0.7946034 0.2568374 -0.6567597 1.2451387 -0.8375699
#'
#' @export
repeatable <- function(rngfunc, seed = runif(1, 0, .Machine$integer.max)) {
force(seed)
function(...) {
# When we exit, restore the seed to its original state
if (exists('.Random.seed', where=globalenv())) {
currentSeed <- get('.Random.seed', pos=globalenv())
on.exit(assign('.Random.seed', currentSeed, pos=globalenv()))
}
else {
on.exit(rm('.Random.seed', pos=globalenv()))
}
set.seed(seed)
rngfunc(...)
}
}
# Temporarily set x in env to value, evaluate expr, and
# then restore x to its original state
withTemporary <- function(env, x, value, expr, unset = FALSE) {
if (exists(x, envir = env, inherits = FALSE)) {
oldValue <- get(x, envir = env, inherits = FALSE)
on.exit(
assign(x, oldValue, envir = env, inherits = FALSE),
add = TRUE)
} else {
on.exit(
rm(list = x, envir = env, inherits = FALSE),
add = TRUE
)
}
if (!missing(value) && !isTRUE(unset))
assign(x, value, envir = env, inherits = FALSE)
else {
if (exists(x, envir = env, inherits = FALSE))
rm(list = x, envir = env, inherits = FALSE)
}
force(expr)
}
.globals$ownSeed <- NULL
# Evaluate an expression using Shiny's own private stream of
# randomness (not affected by set.seed).
withPrivateSeed <- function(expr) {
withTemporary(.GlobalEnv, ".Random.seed",
.globals$ownSeed, unset=is.null(.globals$ownSeed), {
tryCatch({
expr
}, finally = {.globals$ownSeed <- .Random.seed})
}
)
}
# Version of runif that runs with private seed
p_runif <- function(...) {
withPrivateSeed(runif(...))
}
# Version of sample that runs with private seed
p_sample <- function(...) {
withPrivateSeed(sample(...))
}
# Return a random integral value in the range [min, max).
# If only one argument is passed, then min=0 and max=argument.
randomInt <- function(min, max) {
if (missing(max)) {
max <- min
min <- 0
}
if (min < 0 || max <= min)
stop("Invalid min/max values")
min + sample(max-min, 1)-1
}
p_randomInt <- function(...) {
withPrivateSeed(randomInt(...))
}
`%OR%` <- function(x, y) {
if (is.null(x) || isTRUE(is.na(x)))
y
else
x
}
`%AND%` <- function(x, y) {
if (!is.null(x) && !is.na(x))
if (!is.null(y) && !is.na(y))
return(y)
return(NULL)
}
`%.%` <- function(x, y) {
paste(x, y, sep='')
}
# Given a vector or list, drop all the NULL items in it
dropNulls <- function(x) {
x[!vapply(x, is.null, FUN.VALUE=logical(1))]
}
nullOrEmpty <- function(x) {
is.null(x) || length(x) == 0
}
# Given a vector or list, drop all the NULL items in it
dropNullsOrEmpty <- function(x) {
x[!vapply(x, nullOrEmpty, FUN.VALUE=logical(1))]
}
# Combine dir and (file)name into a file path. If a file already exists with a
# name differing only by case, then use it instead.
file.path.ci <- function(dir, name) {
default <- file.path(dir, name)
if (file.exists(default))
return(default)
if (!file.exists(dir))
return(default)
matches <- list.files(dir, name, ignore.case=TRUE, full.names=TRUE,
include.dirs=TRUE)
if (length(matches) == 0)
return(default)
return(matches[[1]])
}
# Attempt to join a path and relative path, and turn the result into a
# (normalized) absolute path. The result will only be returned if it is an
# existing file/directory and is a descendant of dir.
#
# Example:
# resolve("/Users/jcheng", "shiny") # "/Users/jcheng/shiny"
# resolve("/Users/jcheng", "./shiny") # "/Users/jcheng/shiny"
# resolve("/Users/jcheng", "shiny/../shiny/") # "/Users/jcheng/shiny"
# resolve("/Users/jcheng", ".") # NULL
# resolve("/Users/jcheng", "..") # NULL
# resolve("/Users/jcheng", "shiny/..") # NULL
resolve <- function(dir, relpath) {
abs.path <- file.path(dir, relpath)
if (!file.exists(abs.path))
return(NULL)
abs.path <- normalizePath(abs.path, winslash='/', mustWork=TRUE)
dir <- normalizePath(dir, winslash='/', mustWork=TRUE)
# trim the possible trailing slash under Windows (#306)
if (.Platform$OS.type == 'windows') dir <- sub('/$', '', dir)
if (nchar(abs.path) <= nchar(dir) + 1)
return(NULL)
if (substr(abs.path, 1, nchar(dir)) != dir ||
substr(abs.path, nchar(dir)+1, nchar(dir)+1) != '/') {
return(NULL)
}
return(abs.path)
}
# This is a wrapper for download.file and has the same interface.
# The only difference is that, if the protocol is https, it changes the
# download settings, depending on platform.
download <- function(url, ...) {
# First, check protocol. If http or https, check platform:
if (grepl('^https?://', url)) {
# If Windows, call setInternet2, then use download.file with defaults.
if (.Platform$OS.type == "windows") {
# If we directly use setInternet2, R CMD CHECK gives a Note on Mac/Linux
mySI2 <- `::`(utils, 'setInternet2')
# Store initial settings
internet2_start <- mySI2(NA)
on.exit(mySI2(internet2_start))
# Needed for https
mySI2(TRUE)
download.file(url, ...)
} else {
# If non-Windows, check for curl/wget/lynx, then call download.file with
# appropriate method.
if (nzchar(Sys.which("wget")[1])) {
method <- "wget"
} else if (nzchar(Sys.which("curl")[1])) {
method <- "curl"
# curl needs to add a -L option to follow redirects.
# Save the original options and restore when we exit.
orig_extra_options <- getOption("download.file.extra")
on.exit(options(download.file.extra = orig_extra_options))
options(download.file.extra = paste("-L", orig_extra_options))
} else if (nzchar(Sys.which("lynx")[1])) {
method <- "lynx"
} else {
stop("no download method found")
}
download.file(url, method = method, ...)
}
} else {
download.file(url, ...)
}
}
knownContentTypes <- Map$new()
knownContentTypes$mset(
html='text/html; charset=UTF-8',
htm='text/html; charset=UTF-8',
js='text/javascript',
css='text/css',
png='image/png',
jpg='image/jpeg',
jpeg='image/jpeg',
gif='image/gif',
svg='image/svg+xml',
txt='text/plain',
pdf='application/pdf',
ps='application/postscript',
xml='application/xml',
m3u='audio/x-mpegurl',
m4a='audio/mp4a-latm',
m4b='audio/mp4a-latm',
m4p='audio/mp4a-latm',
mp3='audio/mpeg',
wav='audio/x-wav',
m4u='video/vnd.mpegurl',
m4v='video/x-m4v',
mp4='video/mp4',
mpeg='video/mpeg',
mpg='video/mpeg',
avi='video/x-msvideo',
mov='video/quicktime',
ogg='application/ogg',
swf='application/x-shockwave-flash',
doc='application/msword',
xls='application/vnd.ms-excel',
ppt='application/vnd.ms-powerpoint',
xlsx='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
xltx='application/vnd.openxmlformats-officedocument.spreadsheetml.template',
potx='application/vnd.openxmlformats-officedocument.presentationml.template',
ppsx='application/vnd.openxmlformats-officedocument.presentationml.slideshow',
pptx='application/vnd.openxmlformats-officedocument.presentationml.presentation',
sldx='application/vnd.openxmlformats-officedocument.presentationml.slide',
docx='application/vnd.openxmlformats-officedocument.wordprocessingml.document',
dotx='application/vnd.openxmlformats-officedocument.wordprocessingml.template',
xlam='application/vnd.ms-excel.addin.macroEnabled.12',
xlsb='application/vnd.ms-excel.sheet.binary.macroEnabled.12')
getContentType <- function(ext, defaultType='application/octet-stream') {
knownContentTypes$get(tolower(ext)) %OR% defaultType
}
# Create a zero-arg function from a quoted expression and environment
# @examples
# makeFunction(body=quote(print(3)))
makeFunction <- function(args = pairlist(), body, env = parent.frame()) {
eval(call("function", args, body), env)
}
#' Convert an expression to a function
#'
#' This is to be called from another function, because it will attempt to get
#' an unquoted expression from two calls back.
#'
#' If expr is a quoted expression, then this just converts it to a function.
#' If expr is a function, then this simply returns expr (and prints a
#' deprecation message).
#' If expr was a non-quoted expression from two calls back, then this will
#' quote the original expression and convert it to a function.
#
#' @param expr A quoted or unquoted expression, or a function.
#' @param env The desired environment for the function. Defaults to the
#' calling environment two steps back.
#' @param quoted Is the expression quoted?
#' @param caller_offset If specified, the offset in the callstack of the
#' functiont to be treated as the caller.
#'
#' @examples
#' # Example of a new renderer, similar to renderText
#' # This is something that toolkit authors will do
#' renderTriple <- function(expr, env=parent.frame(), quoted=FALSE) {
#' # Convert expr to a function
#' func <- shiny::exprToFunction(expr, env, quoted)
#'
#' function() {
#' value <- func()
#' paste(rep(value, 3), collapse=", ")
#' }
#' }
#'
#'
#' # Example of using the renderer.
#' # This is something that app authors will do.
#' values <- reactiveValues(A="text")
#'
#' \dontrun{
#' # Create an output object
#' output$tripleA <- renderTriple({
#' values$A
#' })
#' }
#'
#' # At the R console, you can experiment with the renderer using isolate()
#' tripleA <- renderTriple({
#' values$A
#' })
#'
#' isolate(tripleA())
#' # "text, text, text"
#'
#' @export
exprToFunction <- function(expr, env=parent.frame(2), quoted=FALSE,
caller_offset=1) {
# Get the quoted expr from two calls back
expr_sub <- eval(substitute(substitute(expr)), parent.frame(caller_offset))
# Check if expr is a function, making sure not to evaluate expr, in case it
# is actually an unquoted expression.
# If expr is a single token, then indexing with [[ will error; if it has multiple
# tokens, then [[ works. In the former case it will be a name object; in the
# latter, it will be a language object.
if (!is.null(expr_sub) && !is.name(expr_sub) && expr_sub[[1]] == as.name('function')) {
# Get name of function that called this function
called_fun <- sys.call(-1 * caller_offset)[[1]]
shinyDeprecated(msg = paste("Passing functions to '", called_fun,
"' is deprecated. Please use expressions instead. See ?", called_fun,
" for more information.", sep=""))
return(expr)
}
if (quoted) {
# expr is a quoted expression
makeFunction(body=expr, env=env)
} else {
# expr is an unquoted expression
makeFunction(body=expr_sub, env=env)
}
}
#' Install an expression as a function
#'
#' Installs an expression in the given environment as a function, and registers
#' debug hooks so that breakpoints may be set in the function.
#'
#' This function can replace \code{exprToFunction} as follows: we may use
#' \code{func <- exprToFunction(expr)} if we do not want the debug hooks, or
#' \code{installExprFunction(expr, "func")} if we do. Both approaches create a
#' function named \code{func} in the current environment.
#'
#' @seealso Wraps \code{\link{exprToFunction}}; see that method's documentation
#' for more documentation and examples.
#'
#' @param expr A quoted or unquoted expression
#' @param name The name the function should be given
#' @param eval.env The desired environment for the function. Defaults to the
#' calling environment two steps back.
#' @param quoted Is the expression quoted?
#' @param assign.env The environment in which the function should be assigned.
#' @param label A label for the object to be shown in the debugger. Defaults to
#' the name of the calling function.
#'
#' @export
installExprFunction <- function(expr, name, eval.env = parent.frame(2),
quoted = FALSE,
assign.env = parent.frame(1),
label = as.character(sys.call(-1)[[1]])) {
func <- exprToFunction(expr, eval.env, quoted, 2)
assign(name, func, envir = assign.env)
registerDebugHook(name, assign.env, label)
}
#' Parse a GET query string from a URL
#'
#' Returns a named character vector of key-value pairs.
#'
#' @param str The query string. It can have a leading \code{"?"} or not.
#' @export
#' @examples
#' parseQueryString("?foo=1&bar=b%20a%20r")
#'
#' \dontrun{
#' # Example of usage within a Shiny app
#' shinyServer(function(input, output, clientData) {
#'
#' output$queryText <- renderText({
#' query <- parseQueryString(clientData$url_search)
#'
#' # Ways of accessing the values
#' if (as.numeric(query$foo) == 1) {
#' # Do something
#' }
#' if (query[["bar"]] == "targetstring") {
#' # Do something else
#' }
#'
#' # Return a string with key-value pairs
#' paste(names(query), query, sep = "=", collapse=", ")
#' })
#' })
#' }
#'
parseQueryString <- function(str) {
if (is.null(str) || nchar(str) == 0)
return(list())
# Remove leading ?
if (substr(str, 1, 1) == '?')
str <- substr(str, 2, nchar(str))
pairs <- strsplit(str, '&', fixed = TRUE)[[1]]
pairs <- strsplit(pairs, '=', fixed = TRUE)
keys <- vapply(pairs, function(x) x[1], FUN.VALUE = character(1))
values <- vapply(pairs, function(x) x[2], FUN.VALUE = character(1))
# Replace NA with '', so they don't get converted to 'NA' by URLdecode
values[is.na(values)] <- ''
# Convert "+" to " ", since URLdecode doesn't do it
keys <- gsub('+', ' ', keys, fixed = TRUE)
values <- gsub('+', ' ', values, fixed = TRUE)
keys <- vapply(keys, function(x) URLdecode(x), FUN.VALUE = character(1))
values <- vapply(values, function(x) URLdecode(x), FUN.VALUE = character(1))
setNames(as.list(values), keys)
}
# decide what to do in case of errors; it is customizable using the shiny.error
# option (e.g. we can set options(shiny.error = recover))
shinyCallingHandlers <- function(expr) {
withCallingHandlers(expr, error = function(e) {
handle <- getOption('shiny.error')
if (is.function(handle)) handle()
})
}
#' Print message for deprecated functions in Shiny
#'
#' To disable these messages, use \code{options(shiny.deprecation.messages=FALSE)}.
#'
#' @param new Name of replacement function.
#' @param msg Message to print. If used, this will override the default message.
#' @param old Name of deprecated function.
shinyDeprecated <- function(new=NULL, msg=NULL,
old=as.character(sys.call(sys.parent()))[1L]) {
if (getOption("shiny.deprecation.messages", default=TRUE) == FALSE)
return(invisible())
if (is.null(msg)) {
msg <- paste(old, "is deprecated.")
if (!is.null(new))
msg <- paste(msg, "Please use", new, "instead.",
"To disable this message, run options(shiny.deprecation.messages=FALSE)")
}
# Similar to .Deprecated(), but print a message instead of warning
message(msg)
}
#' Register a function with the debugger (if one is active).
#'
#' Call this function after exprToFunction to give any active debugger a hook
#' to set and clear breakpoints in the function. A debugger may implement
#' registerShinyDebugHook to receive callbacks when Shiny functions are
#' instantiated at runtime.
#'
#' @param name Name of the field or object containing the function.
#' @param where The reference object or environment containing the function.
#' @param label A label to display on the function in the debugger.
#' @noRd
registerDebugHook <- function(name, where, label) {
if (exists("registerShinyDebugHook", mode = "function")) {
registerShinyDebugHook <- get("registerShinyDebugHook", mode = "function")
params <- new.env(parent = emptyenv())
params$name <- name
params$where <- where
params$label <- label
registerShinyDebugHook(params)
}
}
Callbacks <- setRefClass(
'Callbacks',
fields = list(
.nextId = 'integer',
.callbacks = 'Map'
),
methods = list(
initialize = function() {
.nextId <<- as.integer(.Machine$integer.max)
},
register = function(callback) {
id <- as.character(.nextId)
.nextId <<- .nextId - 1L
.callbacks$set(id, callback)
return(function() {
.callbacks$remove(id)
})
},
invoke = function(..., onError=NULL) {
for (callback in .callbacks$values()) {
if (is.null(onError)) {
callback(...)
} else {
tryCatch(callback(...), error = onError)
}
}
},
count = function() {
.callbacks$size()
}
)
)
# convert a data frame to JSON as required by DataTables request
dataTablesJSON <- function(data, req) {
query <- req$QUERY_STRING
n <- nrow(data)
with(parseQueryString(query), {
useRegex <- function(j, envir = parent.frame()) {
# FIXME: bRegex is not part of the query string yet (DataTables 1.9.4)
return(TRUE)
ex <- getExists(
if (missing(j)) 'bRegex' else sprintf('bRegex_%s', j), 'character', envir
)
is.null(ex) || ex == 'true'
}
# global searching
i <- seq_len(n)
sSearch <- getExists('sSearch', 'character')
if (length(sSearch) && nzchar(sSearch)) {
bRegex <- useRegex()
i0 <- apply(data, 2, function(x) grep(sSearch, as.character(x), fixed = !bRegex))
i <- intersect(i, unique(unlist(i0)))
}
# search by columns
if (length(i)) for (j in seq_len(as.integer(iColumns)) - 1) {
if (is.null(s <- getExists(sprintf('bSearchable_%d', j), 'character')) ||
s == "0" || s == "false") next # the j-th column is not searchable
if (is.null(k <- getExists(sprintf('sSearch_%d', j), 'character'))) next
if (nzchar(k)) {
dj <- data[, j + 1]
r <- commaToRange(k)
ij <- if (length(r) == 2 && is.numeric(dj)) {
which(dj >= r[1] & dj <= r[2])
} else {
grep(k, as.character(dj), fixed = !useRegex(j))
}
i <- intersect(ij, i)
}
if (length(i) == 0) break
}
if (length(i) != n) data <- data[i, , drop = FALSE]
# sorting
oList <- list()
for (j in seq_len(as.integer(iSortingCols)) - 1) {
if (is.null(k <- getExists(sprintf('iSortCol_%d', j), 'character'))) break
desc <- getExists(sprintf('sSortDir_%d', j), 'character')
if (is.character(desc)) {
col <- data[, as.integer(k) + 1]
oList[[length(oList) + 1]] <- (if (desc == 'asc') identity else `-`)(
if (is.numeric(col)) col else xtfrm(col)
)
}
}
if (length(oList)) {
i <- do.call(order, oList)
data <- data[i, , drop = FALSE]
}
# paging
if (iDisplayLength != '-1') {
i <- seq(as.integer(iDisplayStart) + 1L, length.out = as.integer(iDisplayLength))
i <- i[i <= nrow(data)]
fdata <- data[i, , drop = FALSE] # filtered data
} else fdata <- data
fdata <- unname(as.matrix(fdata))
# WAT: toJSON(list(x = matrix(nrow = 0, ncol = 1))) => {"x": } (#299)
if (nrow(fdata) == 0) fdata <- list()
# WAT: toJSON(list(x = matrix(1:2))) => {x: [ [1], [2] ]}, however,
# toJSON(list(x = matrix(1))) => {x: [ 1 ]} (loss of dimension, #429)
if (all(dim(fdata) == 1)) fdata <- list(list(fdata[1, 1]))
res <- toJSON(list(
sEcho = as.integer(sEcho),
iTotalRecords = n,
iTotalDisplayRecords = nrow(data),
aaData = fdata
))
httpResponse(200, 'application/json', res)
})
}
getExists <- function(x, mode, envir = parent.frame()) {
if (exists(x, envir = envir, mode = mode, inherits = FALSE))
get(x, envir = envir, mode = mode, inherits = FALSE)
}
# convert a string of the form "lower,upper" to c(lower, upper)
commaToRange <- function(string) {
if (!grepl(',', string)) return()
r <- strsplit(string, ',')[[1]]
if (length(r) > 2) return()
if (length(r) == 1) r <- c(r, '') # lower,
r <- as.numeric(r)
if (is.na(r[1])) r[1] <- -Inf
if (is.na(r[2])) r[2] <- Inf
r
}
# for options passed to DataTables/Selectize/..., the options of the class AsIs
# will be evaluated as literal JavaScript code
checkAsIs <- function(options) {
evalOptions <- if (length(options)) {
nms <- names(options)
i <- unlist(lapply(options, function(x) {
is.character(x) && inherits(x, 'AsIs')
}))
if (any(i)) {
# must convert to character, otherwise toJSON() turns it to an array []
options[i] <- lapply(options[i], paste, collapse = '\n')
nms[i] # options of these names will be evaluated in JS
}
}
list(options = options, eval = evalOptions)
}
srcrefFromShinyCall <- function(expr) {
srcrefs <- attr(expr, "srcref")
num_exprs <- length(srcrefs)
if (num_exprs < 1)
return(NULL)
c(srcrefs[[1]][1], srcrefs[[1]][2],
srcrefs[[num_exprs]][3], srcrefs[[num_exprs]][4],
srcrefs[[1]][5], srcrefs[[num_exprs]][6])
}
# Indicates whether the given querystring should cause the associated request
# to be handled in showcase mode. Returns the showcase mode if set, or NULL
# if no showcase mode is set.
showcaseModeOfQuerystring <- function(querystring) {
if (nchar(querystring) > 0) {
qs <- parseQueryString(querystring)
if (exists("showcase", where = qs)) {
return(as.numeric(qs$showcase))
}
}
return(NULL)
}
showcaseModeOfReq <- function(req) {
showcaseModeOfQuerystring(req$QUERY_STRING)
}
# Returns (just) the filename containing the given source reference, or an
# empty string if the source reference doesn't include file information.
srcFileOfRef <- function(srcref) {
fileEnv <- attr(srcref, "srcfile")
# The 'srcfile' attribute should be a non-null environment containing the
# variable 'filename', which gives the full path to the source file.
if (!is.null(fileEnv) &&
is.environment(fileEnv) &&
exists("filename", where = fileEnv))
basename(fileEnv[["filename"]])
else
""
}
# Format a number without sci notation, and keep as many digits as possible (do
# we really need to go beyond 15 digits?)
formatNoSci <- function(x) {
if (is.null(x)) return(NULL)
format(x, scientific = FALSE, digits = 15)
}
# Returns a function that calls the given func and caches the result for
# subsequent calls, unless the given file's mtime changes.
cachedFuncWithFile <- function(dir, file, func, case.sensitive = FALSE) {
dir <- normalizePath(dir, mustWork=TRUE)
mtime <- NA
value <- NULL
function(...) {
fname <- if (case.sensitive)
file.path(dir, file)
else
file.path.ci(dir, file)
now <- file.info(fname)$mtime
if (!identical(mtime, now)) {
value <<- func(fname, ...)
mtime <<- now
}
value
}
}
# Returns a function that sources the file and caches the result for subsequent
# calls, unless the file's mtime changes.
cachedSource <- function(dir, file, case.sensitive = FALSE) {
dir <- normalizePath(dir, mustWork=TRUE)
cachedFuncWithFile(dir, file, function(fname, ...) {
if (file.exists(fname))
return(source(fname, ...))
else
return(NULL)
})
}
# turn column-based data to row-based data (mainly for JSON), e.g. data.frame(x
# = 1:10, y = 10:1) ==> list(list(x = 1, y = 10), list(x = 2, y = 9), ...)
columnToRowData <- function(data) {
do.call(
mapply, c(
list(FUN = function(...) list(...), SIMPLIFY = FALSE, USE.NAMES = FALSE),
as.list(data)
)
)
}
#' Validate input values and other conditions
#'
#' For an output rendering function (e.g. \code{\link{renderPlot}()}), you may
#' need to check that certain input values are available and valid before you
#' can render the output. \code{validate} gives you a convenient mechanism for
#' doing so.
#'
#' The \code{validate} function takes any number of (unnamed) arguments, each of
#' which represents a condition to test. If any of the conditions represent
#' failure, then a special type of error is signaled which stops execution. If
#' this error is not handled by application-specific code, it is displayed to
#' the user by Shiny.
#'
#' An easy way to provide arguments to \code{validate} is to use the \code{need}
#' function, which takes an expression and a string; if the expression is
#' considered a failure, then the string will be used as the error message. The
#' \code{need} function considers its expression to be a failure if it is any of
#' the following:
#'
#' \itemize{
#' \item{\code{FALSE}}
#' \item{\code{NULL}}
#' \item{\code{""}}
#' \item{An empty atomic vector}
#' \item{An atomic vector that contains only missing values}
#' \item{A logical vector that contains all \code{FALSE} or missing values}
#' \item{An object of class \code{"try-error"}}
#' \item{A value that represents an unclicked \code{\link{actionButton}}}
#' }
#'
#' If any of these values happen to be valid, you can explicitly turn them to
#' logical values. For example, if you allow \code{NA} but not \code{NULL}, you
#' can use the condition \code{!is.null(input$foo)}, because \code{!is.null(NA)
#' == TRUE}.
#'
#' If you need validation logic that differs significantly from \code{need}, you
#' can create other validation test functions. A passing test should return
#' \code{NULL}. A failing test should return an error message as a
#' single-element character vector, or if the failure should happen silently,
#' \code{FALSE}.
#'
#' Because validation failure is signaled as an error, you can use
#' \code{validate} in reactive expressions, and validation failures will
#' automatically propagate to outputs that use the reactive expression. In
#' other words, if reactive expression \code{a} needs \code{input$x}, and two
#' outputs use \code{a} (and thus depend indirectly on \code{input$x}), it's
#' not necessary for the outputs to validate \code{input$x} explicitly, as long
#' as \code{a} does validate it.
#'
#' @param ... A list of tests. Each test should equal \code{NULL} for success,
#' \code{FALSE} for silent failure, or a string for failure with an error
#' message.
#' @param errorClass A CSS class to apply. The actual CSS string will have
#' \code{shiny-output-error-} prepended to this value.
#' @export
#' @examples
#' # in ui.R
#' fluidPage(
#' checkboxGroupInput('in1', 'Check some letters', choices = head(LETTERS)),
#' selectizeInput('in2', 'Select a state', choices = state.name),
#' plotOutput('plot')
#' )
#'
#' # in server.R
#' function(input, output) {
#' output$plot <- renderPlot({
#' validate(
#' need(input$in1, 'Check at least one letter!'),
#' need(input$in2 == '', 'Please choose a state.')
#' )
#' plot(1:10, main = paste(c(input$in1, input$in2), collapse = ', '))
#' })
#' }
validate <- function(..., errorClass = character(0)) {
results <- sapply(list(...), function(x) {
# Detect NULL or NA
if (is.null(x))
return(NA_character_)
else if (identical(x, FALSE))
return("")
else if (is.character(x))
return(paste(as.character(x), collapse = "\n"))
else
stop("Unexpected validation result: ", as.character(x))
})
results <- na.omit(results)
if (length(results) == 0)
return(invisible())
# There may be empty strings remaining; these are message-less failures that
# started as FALSE
results <- results[nzchar(results)]
stopWithCondition(c("validation", errorClass), paste(results, collapse="\n"))
}
#' @param expr An expression to test. The condition will pass if the expression
#' meets the conditions spelled out in Details.
#' @param message A message to convey to the user if the validation condition is
#' not met. If no message is provided, one will be created using \code{label}.
#' To fail with no message, use \code{FALSE} for the message.
#' @param label A human-readable name for the field that may be missing. This
#' parameter is not needed if \code{message} is provided, but must be provided
#' otherwise.
#' @export
#' @rdname validate
need <- function(expr, message = paste(label, "must be provided"), label) {
force(message) # Fail fast on message/label both being missing
if (!isTruthy(expr))
return(message)
else
return(invisible(NULL))
}
isTruthy <- function(x) {
if (inherits(x, 'try-error'))
return(FALSE)
if (!is.atomic(x))
return(TRUE)
if (is.null(x))
return(FALSE)
if (length(x) == 0)
return(FALSE)
if (all(is.na(x)))
return(FALSE)
if (is.character(x) && !any(nzchar(na.omit(x))))
return(FALSE)
if (inherits(x, 'shinyActionButtonValue') && x == 0)
return(FALSE)
if (is.logical(x) && !any(na.omit(x)))
return(FALSE)
return(TRUE)
}
# add class(es) to the error condition, which will be used as names of CSS
# classes, e.g. shiny-output-error shiny-output-error-validation
stopWithCondition <- function(class, message) {
cond <- structure(
list(message = message),
class = c(class, 'shiny.silent.error', 'error', 'condition')
)
stop(cond)
}

View File

@@ -1,10 +1,49 @@
# Shiny
### A web framework for R (eventually--Ruby for now)
```sh
sudo apt-get install ruby1.9.1 ruby1.9.1-dev
sudo gem install bundler
cd shiny
bundle install --path vendor
./run.sh
```
[![Build Status](https://travis-ci.org/rstudio/shiny.png)](https://travis-ci.org/rstudio/shiny)
Shiny is a new package from RStudio that makes it incredibly easy to build interactive web applications with R.
For an introduction and examples, visit the [Shiny homepage](http://www.rstudio.com/shiny/).
## Features
* Build useful web applications with only a few lines of code&mdash;no JavaScript required.
* Shiny applications are automatically "live" in the same way that spreadsheets are live. Outputs change instantly as users modify inputs, without requiring a reload of the browser.
* Shiny user interfaces can be built entirely using R, or can be written directly in HTML, CSS, and JavaScript for more flexibility.
* Works in any R environment (Console R, Rgui for Windows or Mac, ESS, StatET, RStudio, etc.)
* Attractive default UI theme based on [Bootstrap](http://getbootstrap.com/2.3.2/).
* A highly customizable slider widget with built-in support for animation.
* Pre-built output widgets for displaying plots, tables, and printed output of R objects.
* Fast bidirectional communication between the web browser and R using the [httpuv](https://github.com/rstudio/httpuv) package.
* Uses a [reactive](http://en.wikipedia.org/wiki/Reactive_programming) programming model that eliminates messy event handling code, so you can focus on the code that really matters.
* Develop and redistribute your own Shiny widgets that other developers can easily drop into their own applications (coming soon!).
## Installation
To install the stable version from CRAN, simply run the following from an R console:
```r
install.packages("shiny")
```
To install the latest development builds directly from GitHub, run this instead:
```r
if (!require("devtools"))
install.packages("devtools")
devtools::install_github("shiny", "rstudio")
```
## Getting Started
To learn more we highly recommend you check out the [Shiny Tutorial](http://rstudio.github.com/shiny/tutorial). The tutorial explains the framework in-depth, walks you through building a simple application, and includes extensive annotated examples.
We hope you enjoy using Shiny. If you have general questions about using Shiny, please use the Shiny [mailing list](https://groups.google.com/forum/#!forum/shiny-discuss). For bug reports, please use the [issue tracker](https://github.com/rstudio/shiny/issues).
## License
The shiny package is licensed under the GPLv3. See these files in the inst directory for additional details:
- COPYING - shiny package license (GPLv3)
- NOTICE - Copyright notices for additional included software

View File

@@ -1,15 +0,0 @@
library(digest)
input <- Observable$new(function() {
str <- get.shiny.input('input1')
if (get.shiny.input('addnewline'))
str <- paste(str, "\n", sep='')
return(str)
})
define.shiny.output('md5_hash', function() {
digest(input$get.value(), algo='md5', serialize=F)
})
define.shiny.output('sha1_hash', function() {
digest(input$get.value(), algo='sha1', serialize=F)
})

View File

@@ -1,26 +0,0 @@
<html>
<head>
<script src="shared/jquery-1.7.2.js" type="text/javascript"></script>
<script src="shared/shiny.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="shared/shiny.css"/>
</head>
<body>
<h1>Example 2: Hash Calculation</h1>
<p>
<label>Input:</label><br />
<input name="input1" value="Hello World!"/>
<input type="checkbox" name="addnewline" checked="checked"/> Append newline
</p>
<p>
<label>MD5:</label><br />
<pre id="md5_hash" class="live-text"></pre>
</p>
<p>
<label>SHA-1:</label><br />
<pre id="sha1_hash" class="live-text"></pre>
</p>
</body>
</html>

View File

@@ -1,24 +0,0 @@
data <- Observable$new(function() {
# Choose a distribution function
dist <- switch(get.shiny.input('dist'),
norm = rnorm,
unif = runif,
lnorm = rlnorm,
exp = rexp,
rnorm)
# Generate n values from the distribution function
dist(max(1, get.shiny.input('n')))
})
define.shiny.plot('plot1', function() {
dist <- get.shiny.input('dist')
n <- get.shiny.input('n')
hist(data$get.value(),
main=paste('r', dist, '(', n, ')', sep=''))
}, width=600, height=300)
define.shiny.table('table1', function() {
data.frame(x=data$get.value())
})

19
hash.rb
View File

@@ -1,19 +0,0 @@
require 'shiny'
require 'digest/sha1'
require 'digest/md5'
shinyapp = ShinyApp.new
input1 = React::ObservableValue.new {
shinyapp.session.get('input1') + (shinyapp.session.get('addnewline') ? "\n" : '')
}
shinyapp.define_output('md5_hash') do
Digest::MD5.hexdigest(input1.value)
end
shinyapp.define_output('sha1_hash') do
Digest::SHA1.hexdigest(input1.value)
end
shinyapp.run

678
inst/COPYING Normal file
View File

@@ -0,0 +1,678 @@
The shiny package is licensed to you under the GPLv3, the terms of
which are included below. The markdown pacakge includes other open
source software whose license terms can be found in the file NOTICE.
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
<program> Copyright (C) <year> <name of author>
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
<http://www.gnu.org/licenses/>.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<http://www.gnu.org/philosophy/why-not-lgpl.html>.

325
inst/NOTICE Normal file
View File

@@ -0,0 +1,325 @@
The shiny package inludes other open source software components. The following
is a list of these components (full copies of the license agreements used by
these components are included below):
- jQuery
- Bootstrap
- bootstrap-datepicker, from https://github.com/eternicode/bootstrap-datepicker
- selectize, from https://github.com/brianreavis/selectize.js
- es5-shim
- jslider
- DataTables
jQuery License
----------------------------------------------------------------------
Copyright (c) 2012 jQuery Foundation and other contributors,
http://jquery.com/
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Bootstrap, bootstrap-datepicker, and selectize License
----------------------------------------------------------------------
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
es5-shim License
----------------------------------------------------------------------
The MIT License (MIT)
Copyright (C) 2009-2014 Kristopher Michael Kowal and contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
jslider License
----------------------------------------------------------------------
The MIT License (MIT)
Copyright (c) 2012 Egor Khmelev
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
DataTables License
----------------------------------------------------------------------
Copyright (c) 2008-2010, Allan Jardine
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of Allan Jardine nor SpryMedia UK may be used to
endorse or promote products derived from this software without specific
prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS "AS IS" AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

View File

@@ -0,0 +1,7 @@
Title: Hello Shiny!
Author: RStudio, Inc.
AuthorUrl: http://www.rstudio.com/
License: MIT
DisplayMode: Showcase
Tags: getting-started
Type: Shiny

View File

@@ -0,0 +1,4 @@
This small Shiny application demonstrates Shiny's automatic UI updates. Move
the *Number of bins* slider and notice how the `renderPlot` expression is
automatically re-evaluated when its dependant, `input$bins`, changes,
causing a histogram with a new number of bins to be rendered.

View File

@@ -0,0 +1,21 @@
library(shiny)
# Define server logic required to draw a histogram
shinyServer(function(input, output) {
# Expression that generates a histogram. The expression is
# wrapped in a call to renderPlot to indicate that:
#
# 1) It is "reactive" and therefore should be automatically
# re-executed when inputs change
# 2) Its output type is a plot
output$distPlot <- renderPlot({
x <- faithful[, 2] # Old Faithful Geyser data
bins <- seq(min(x), max(x), length.out = input$bins + 1)
# draw the histogram with the specified number of bins
hist(x, breaks = bins, col = 'darkgray', border = 'white')
})
})

View File

@@ -0,0 +1,24 @@
library(shiny)
# Define UI for application that draws a histogram
shinyUI(fluidPage(
# Application title
titlePanel("Hello Shiny!"),
# Sidebar with a slider input for the number of bins
sidebarLayout(
sidebarPanel(
sliderInput("bins",
"Number of bins:",
min = 1,
max = 50,
value = 30)
),
# Show a plot of the generated distribution
mainPanel(
plotOutput("distPlot")
)
)
))

View File

@@ -0,0 +1,8 @@
Title: Shiny Text
Author: RStudio, Inc.
AuthorUrl: http://www.rstudio.com/
License: MIT
DisplayMode: Showcase
Tags: getting-started
Type: Shiny

View File

@@ -0,0 +1 @@
This example demonstrates output of raw text from R using the `renderPrint` function in `server.R` and the `verbatimTextOutput` function in `ui.R`. In this case, a textual summary of the data is shown using R's built-in `summary` function.

View File

@@ -0,0 +1,26 @@
library(shiny)
library(datasets)
# Define server logic required to summarize and view the selected
# dataset
shinyServer(function(input, output) {
# Return the requested dataset
datasetInput <- reactive({
switch(input$dataset,
"rock" = rock,
"pressure" = pressure,
"cars" = cars)
})
# Generate a summary of the dataset
output$summary <- renderPrint({
dataset <- datasetInput()
summary(dataset)
})
# Show the first "n" observations
output$view <- renderTable({
head(datasetInput(), n = input$obs)
})
})

View File

@@ -0,0 +1,27 @@
library(shiny)
# Define UI for dataset viewer application
shinyUI(fluidPage(
# Application title
titlePanel("Shiny Text"),
# Sidebar with controls to select a dataset and specify the
# number of observations to view
sidebarLayout(
sidebarPanel(
selectInput("dataset", "Choose a dataset:",
choices = c("rock", "pressure", "cars")),
numericInput("obs", "Number of observations to view:", 10)
),
# Show a summary of the dataset and an HTML table with the
# requested number of observations
mainPanel(
verbatimTextOutput("summary"),
tableOutput("view")
)
)
))

View File

@@ -0,0 +1,7 @@
Title: Reactivity
Author: RStudio, Inc.
AuthorUrl: http://www.rstudio.com/
License: MIT
DisplayMode: Showcase
Tags: getting-started
Type: Shiny

View File

@@ -0,0 +1,5 @@
This example demonstrates a core feature of Shiny: **reactivity**. In `server.R`, a reactive called `datasetInput` is declared.
Notice that the reactive expression depends on the input expression `input$dataset`, and that it's used by both the output expression `output$summary` and `output$view`. Try changing the dataset (using *Choose a dataset*) while looking at the reactive and then at the outputs; you will see first the reactive and then its dependencies flash.
Notice also that the reactive expression doesn't just update whenever anything changes--only the inputs it depends on will trigger an update. Change the "Caption" field and notice how only the `output$caption` expression is re-evaluated; the reactive and its dependents are left alone.

View File

@@ -0,0 +1,53 @@
library(shiny)
library(datasets)
# Define server logic required to summarize and view the selected
# dataset
shinyServer(function(input, output) {
# By declaring datasetInput as a reactive expression we ensure
# that:
#
# 1) It is only called when the inputs it depends on changes
# 2) The computation and result are shared by all the callers
# (it only executes a single time)
#
datasetInput <- reactive({
switch(input$dataset,
"rock" = rock,
"pressure" = pressure,
"cars" = cars)
})
# The output$caption is computed based on a reactive expression
# that returns input$caption. When the user changes the
# "caption" field:
#
# 1) This function is automatically called to recompute the
# output
# 2) The new caption is pushed back to the browser for
# re-display
#
# Note that because the data-oriented reactive expressions
# below don't depend on input$caption, those expressions are
# NOT called when input$caption changes.
output$caption <- renderText({
input$caption
})
# The output$summary depends on the datasetInput reactive
# expression, so will be re-executed whenever datasetInput is
# invalidated
# (i.e. whenever the input$dataset changes)
output$summary <- renderPrint({
dataset <- datasetInput()
summary(dataset)
})
# The output$view depends on both the databaseInput reactive
# expression and input$obs, so will be re-executed whenever
# input$dataset or input$obs is changed.
output$view <- renderTable({
head(datasetInput(), n = input$obs)
})
})

View File

@@ -0,0 +1,34 @@
library(shiny)
# Define UI for dataset viewer application
shinyUI(fluidPage(
# Application title
titlePanel("Reactivity"),
# Sidebar with controls to provide a caption, select a dataset,
# and specify the number of observations to view. Note that
# changes made to the caption in the textInput control are
# updated in the output area immediately as you type
sidebarLayout(
sidebarPanel(
textInput("caption", "Caption:", "Data Summary"),
selectInput("dataset", "Choose a dataset:",
choices = c("rock", "pressure", "cars")),
numericInput("obs", "Number of observations to view:", 10)
),
# Show the caption, a summary of the dataset and an HTML
# table with the requested number of observations
mainPanel(
h3(textOutput("caption", container = span)),
verbatimTextOutput("summary"),
tableOutput("view")
)
)
))

View File

@@ -0,0 +1,7 @@
Title: Miles Per Gallon
Author: RStudio, Inc.
AuthorUrl: http://www.rstudio.com/
License: MIT
DisplayMode: Showcase
Tags: getting-started
Type: Shiny

View File

@@ -0,0 +1,4 @@
This example demonstrates the following concepts:
* **Global variables**: The `mpgData` variable is declared outside the `shinyServer` function. This makes it available anywhere inside `shinyServer`. The code in `server.R` outside `shinyServer` is only run once when the app starts up, so it can't contain user input.
* **Reactive expressions**: `formulaText` is a reactive expression. Note how it re-evaluates when the Variable field is changed, but not when the Show Outliers box is ticked.

View File

@@ -0,0 +1,34 @@
library(shiny)
library(datasets)
# We tweak the "am" field to have nicer factor labels. Since
# this doesn't rely on any user inputs we can do this once at
# startup and then use the value throughout the lifetime of the
# application
mpgData <- mtcars
mpgData$am <- factor(mpgData$am, labels = c("Automatic", "Manual"))
# Define server logic required to plot various variables against
# mpg
shinyServer(function(input, output) {
# Compute the forumla text in a reactive expression since it is
# shared by the output$caption and output$mpgPlot functions
formulaText <- reactive({
paste("mpg ~", input$variable)
})
# Return the formula text for printing as a caption
output$caption <- renderText({
formulaText()
})
# Generate a plot of the requested variable against mpg and
# only include outliers if requested
output$mpgPlot <- renderPlot({
boxplot(as.formula(formulaText()),
data = mpgData,
outline = input$outliers)
})
})

29
inst/examples/04_mpg/ui.R Normal file
View File

@@ -0,0 +1,29 @@
library(shiny)
# Define UI for miles per gallon application
shinyUI(fluidPage(
# Application title
titlePanel("Miles Per Gallon"),
# Sidebar with controls to select the variable to plot against
# mpg and to specify whether outliers should be included
sidebarLayout(
sidebarPanel(
selectInput("variable", "Variable:",
c("Cylinders" = "cyl",
"Transmission" = "am",
"Gears" = "gear")),
checkboxInput("outliers", "Show outliers", FALSE)
),
# Show the caption and plot of the requested variable against
# mpg
mainPanel(
h3(textOutput("caption")),
plotOutput("mpgPlot")
)
)
))

View File

@@ -0,0 +1,7 @@
Title: Sliders
Author: RStudio, Inc.
AuthorUrl: http://www.rstudio.com/
License: MIT
DisplayMode: Showcase
Tags: getting-started
Type: Shiny

View File

@@ -0,0 +1,3 @@
This example demonstrates Shiny's versatile `sliderInput` widget.
Slider inputs can be used to select single values, to select a continuous range of values, and even to animate over a range.

View File

@@ -0,0 +1,29 @@
library(shiny)
# Define server logic for slider examples
shinyServer(function(input, output) {
# Reactive expression to compose a data frame containing all of
# the values
sliderValues <- reactive({
# Compose data frame
data.frame(
Name = c("Integer",
"Decimal",
"Range",
"Custom Format",
"Animation"),
Value = as.character(c(input$integer,
input$decimal,
paste(input$range, collapse=' '),
input$format,
input$animation)),
stringsAsFactors=FALSE)
})
# Show the values using an HTML table
output$values <- renderTable({
sliderValues()
})
})

View File

@@ -0,0 +1,43 @@
library(shiny)
# Define UI for slider demo application
shinyUI(fluidPage(
# Application title
titlePanel("Sliders"),
# Sidebar with sliders that demonstrate various available
# options
sidebarLayout(
sidebarPanel(
# Simple integer interval
sliderInput("integer", "Integer:",
min=0, max=1000, value=500),
# Decimal interval with step value
sliderInput("decimal", "Decimal:",
min = 0, max = 1, value = 0.5, step= 0.1),
# Specification of range within an interval
sliderInput("range", "Range:",
min = 1, max = 1000, value = c(200,500)),
# Provide a custom currency format for value display,
# with basic animation
sliderInput("format", "Custom Format:",
min = 0, max = 10000, value = 0, step = 2500,
format="$#,##0", locale="us", animate=TRUE),
# Animation with custom interval (in ms) to control speed,
# plus looping
sliderInput("animation", "Looping Animation:", 1, 2000, 1,
step = 10, animate=
animationOptions(interval=300, loop=TRUE))
),
# Show a table summarizing the values entered
mainPanel(
tableOutput("values")
)
)
))

View File

@@ -0,0 +1,7 @@
Title: Tabsets
Author: RStudio, Inc.
AuthorUrl: http://www.rstudio.com/
License: MIT
DisplayMode: Showcase
Tags: getting-started
Type: Shiny

View File

@@ -0,0 +1,9 @@
This example demonstrates the `tabsetPanel` and `tabPanel` widgets.
Notice that outputs that are not visible are not re-evaluated until they become visible. Try this:
1. Scroll to the bottom of `server.R`
2. Change the number of observations, and observe that only `output$plot` is evaluated.
3. Click the Summary tab, and observe that `output$summary` is evaluated.
4. Change the number of observations again, and observe that now only `output$summary` is evaluated.

View File

@@ -0,0 +1,44 @@
library(shiny)
# Define server logic for random distribution application
shinyServer(function(input, output) {
# Reactive expression to generate the requested distribution.
# This is called whenever the inputs change. The output
# functions defined below then all use the value computed from
# this expression
data <- reactive({
dist <- switch(input$dist,
norm = rnorm,
unif = runif,
lnorm = rlnorm,
exp = rexp,
rnorm)
dist(input$n)
})
# Generate a plot of the data. Also uses the inputs to build
# the plot label. Note that the dependencies on both the inputs
# and the data reactive expression are both tracked, and
# all expressions are called in the sequence implied by the
# dependency graph
output$plot <- renderPlot({
dist <- input$dist
n <- input$n
hist(data(),
main=paste('r', dist, '(', n, ')', sep=''))
})
# Generate a summary of the data
output$summary <- renderPrint({
summary(data())
})
# Generate an HTML table view of the data
output$table <- renderTable({
data.frame(x=data())
})
})

View File

@@ -0,0 +1,38 @@
library(shiny)
# Define UI for random distribution application
shinyUI(fluidPage(
# Application title
titlePanel("Tabsets"),
# Sidebar with controls to select the random distribution type
# and number of observations to generate. Note the use of the
# br() element to introduce extra vertical spacing
sidebarLayout(
sidebarPanel(
radioButtons("dist", "Distribution type:",
c("Normal" = "norm",
"Uniform" = "unif",
"Log-normal" = "lnorm",
"Exponential" = "exp")),
br(),
sliderInput("n",
"Number of observations:",
value = 500,
min = 1,
max = 1000)
),
# Show a tabset that includes a plot, summary, and table view
# of the generated distribution
mainPanel(
tabsetPanel(type = "tabs",
tabPanel("Plot", plotOutput("plot")),
tabPanel("Summary", verbatimTextOutput("summary")),
tabPanel("Table", tableOutput("table"))
)
)
)
))

View File

@@ -0,0 +1,7 @@
Title: Widgets
Author: RStudio, Inc.
AuthorUrl: http://www.rstudio.com/
License: MIT
DisplayMode: Showcase
Tags: getting-started
Type: Shiny

View File

@@ -0,0 +1 @@
This example demonstrates some additional widgets included in Shiny, such as `helpText` and `submitButton`. The latter is used to delay rendering output until the user explicitly requests it.

View File

@@ -0,0 +1,26 @@
library(shiny)
library(datasets)
# Define server logic required to summarize and view the
# selected dataset
shinyServer(function(input, output) {
# Return the requested dataset
datasetInput <- reactive({
switch(input$dataset,
"rock" = rock,
"pressure" = pressure,
"cars" = cars)
})
# Generate a summary of the dataset
output$summary <- renderPrint({
dataset <- datasetInput()
summary(dataset)
})
# Show the first "n" observations
output$view <- renderTable({
head(datasetInput(), n = input$obs)
})
})

View File

@@ -0,0 +1,43 @@
library(shiny)
# Define UI for dataset viewer application
shinyUI(fluidPage(
# Application title.
titlePanel("More Widgets"),
# Sidebar with controls to select a dataset and specify the
# number of observations to view. The helpText function is
# also used to include clarifying text. Most notably, the
# inclusion of a submitButton defers the rendering of output
# until the user explicitly clicks the button (rather than
# doing it immediately when inputs change). This is useful if
# the computations required to render output are inordinately
# time-consuming.
sidebarLayout(
sidebarPanel(
selectInput("dataset", "Choose a dataset:",
choices = c("rock", "pressure", "cars")),
numericInput("obs", "Number of observations to view:", 10),
helpText("Note: while the data view will show only the specified",
"number of observations, the summary will still be based",
"on the full dataset."),
submitButton("Update View")
),
# Show a summary of the dataset and an HTML table with the
# requested number of observations. Note the use of the h4
# function to provide an additional header above each output
# section.
mainPanel(
h4("Summary"),
verbatimTextOutput("summary"),
h4("Observations"),
tableOutput("view")
)
)
))

View File

@@ -0,0 +1,7 @@
Title: Custom HTML UI
Author: RStudio, Inc.
AuthorUrl: http://www.rstudio.com/
License: MIT
DisplayMode: Showcase
Tags: getting-started
Type: Shiny

View File

@@ -0,0 +1,4 @@
Normally we use the built-in functions, such as `textInput()`, to generate
the HTML UI in the R script `ui.R`. Actually **shiny** also works with a
custom HTML page `www/index.html`. See [the
tutorial](http://rstudio.github.io/shiny/tutorial/#html-ui) for more details.

View File

@@ -0,0 +1,42 @@
library(shiny)
# Define server logic for random distribution application
shinyServer(function(input, output) {
# Reactive expression to generate the requested distribution. This is
# called whenever the inputs change. The output expressions defined
# below then all used the value computed from this expression
data <- reactive({
dist <- switch(input$dist,
norm = rnorm,
unif = runif,
lnorm = rlnorm,
exp = rexp,
rnorm)
dist(input$n)
})
# Generate a plot of the data. Also uses the inputs to build the
# plot label. Note that the dependencies on both the inputs and
# the data reactive expression are both tracked, and all expressions
# are called in the sequence implied by the dependency graph
output$plot <- renderPlot({
dist <- input$dist
n <- input$n
hist(data(),
main=paste('r', dist, '(', n, ')', sep=''))
})
# Generate a summary of the data
output$summary <- renderPrint({
summary(data())
})
# Generate an HTML table view of the data
output$table <- renderTable({
data.frame(x=data())
})
})

View File

@@ -1,12 +1,15 @@
<html>
<head>
<script src="shared/jquery-1.7.2.js" type="text/javascript"></script>
<script src="shared/shiny.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="shared/shiny.css"/>
</head>
<body>
<h1>Example 3: Distributions</h1>
<head>
<script src="shared/jquery.js" type="text/javascript"></script>
<script src="shared/shiny.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="shared/shiny.css"/>
</head>
<body>
<h1>HTML UI</h1>
<p>
<label>Distribution type:</label><br />
<select name="dist">
@@ -14,17 +17,22 @@
<option value="unif">Uniform</option>
<option value="lnorm">Log-normal</option>
<option value="exp">Exponential</option>
</select>
</select>
</p>
<p>
<label>Number of observations:</label><br />
<input type="numeric" name="n" value="500" />
</p>
<label>Number of observations:</label><br />
<input type="number" name="n" value="500" min="1" max="1000" />
<div id="plot1" class="live-plot"></div>
</p>
<pre id="summary" class="shiny-text-output"></pre>
<div id="table1" class="live-html"></div>
<div id="plot" class="shiny-plot-output"
style="width: 100%; height: 400px"></div>
<div id="table" class="shiny-html-output"></div>
</body>
</html>
</html>

View File

@@ -0,0 +1,7 @@
Title: File Upload
Author: RStudio, Inc.
AuthorUrl: http://www.rstudio.com/
License: MIT
DisplayMode: Showcase
Tags: getting-started
Type: Shiny

View File

@@ -0,0 +1,4 @@
We can add a file upload input in the UI using the function `fileInput()`,
e.g. `fileInput('foo')`. In `server.R`, we can access the uploaded files via
`input$foo`. See [the
tutorial](http://rstudio.github.io/shiny/tutorial/#uploads) for more details.

View File

@@ -0,0 +1,20 @@
library(shiny)
shinyServer(function(input, output) {
output$contents <- renderTable({
# input$file1 will be NULL initially. After the user selects
# and uploads a file, it will be a data frame with 'name',
# 'size', 'type', and 'datapath' columns. The 'datapath'
# column will contain the local filenames where the data can
# be found.
inFile <- input$file1
if (is.null(inFile))
return(NULL)
read.csv(inFile$datapath, header=input$header, sep=input$sep,
quote=input$quote)
})
})

View File

@@ -0,0 +1,28 @@
library(shiny)
shinyUI(fluidPage(
titlePanel("Uploading Files"),
sidebarLayout(
sidebarPanel(
fileInput('file1', 'Choose CSV File',
accept=c('text/csv',
'text/comma-separated-values,text/plain',
'.csv')),
tags$hr(),
checkboxInput('header', 'Header', TRUE),
radioButtons('sep', 'Separator',
c(Comma=',',
Semicolon=';',
Tab='\t'),
','),
radioButtons('quote', 'Quote',
c(None='',
'Double Quote'='"',
'Single Quote'="'"),
'"')
),
mainPanel(
tableOutput('contents')
)
)
))

View File

@@ -0,0 +1,7 @@
Title: File Download
Author: RStudio, Inc.
AuthorUrl: http://www.rstudio.com/
License: MIT
DisplayMode: Showcase
Tags: getting-started
Type: Shiny

View File

@@ -0,0 +1,4 @@
We can add a download button to the UI using `downloadButton()`, and write
the content of the file in `downloadHandler()` in `server.R`. See [the
tutorial](http://rstudio.github.io/shiny/tutorial/#downloads) for more
details.

View File

@@ -0,0 +1,21 @@
shinyServer(function(input, output) {
datasetInput <- reactive({
switch(input$dataset,
"rock" = rock,
"pressure" = pressure,
"cars" = cars)
})
output$table <- renderTable({
datasetInput()
})
output$downloadData <- downloadHandler(
filename = function() {
paste(input$dataset, '.csv', sep='')
},
content = function(file) {
write.csv(datasetInput(), file)
}
)
})

View File

@@ -0,0 +1,13 @@
shinyUI(fluidPage(
titlePanel('Downloading Data'),
sidebarLayout(
sidebarPanel(
selectInput("dataset", "Choose a dataset:",
choices = c("rock", "pressure", "cars")),
downloadButton('downloadData', 'Download')
),
mainPanel(
tableOutput('table')
)
)
))

View File

@@ -0,0 +1,7 @@
Title: Timer
Author: RStudio, Inc.
AuthorUrl: http://www.rstudio.com/
License: MIT
DisplayMode: Showcase
Tags: getting-started
Type: Shiny

View File

@@ -0,0 +1,4 @@
The function `invalidateLater()` can be used to invalidate an observer or
reactive expression in a given number of milliseconds. In this example, the
output `currentTime` is updated every second, so it shows the current time
on a second basis.

View File

@@ -0,0 +1,6 @@
shinyServer(function(input, output, session) {
output$currentTime <- renderText({
invalidateLater(1000, session)
paste("The current time is", Sys.time())
})
})

View File

@@ -0,0 +1,3 @@
shinyUI(fluidPage(
textOutput("currentTime")
))

164
inst/staticdocs/index.r Normal file
View File

@@ -0,0 +1,164 @@
sd_section("UI Layout",
"Functions for laying out the user interface for your application.",
c(
"absolutePanel",
"bootstrapPage",
"column",
"conditionalPanel",
"fixedPage",
"fluidPage",
"headerPanel",
"helpText",
"icon",
"mainPanel",
"navbarPage",
"navlistPanel",
"pageWithSidebar",
"sidebarLayout",
"sidebarPanel",
"tabPanel",
"tabsetPanel",
"titlePanel",
"inputPanel",
"flowLayout",
"splitLayout",
"verticalLayout",
"wellPanel",
"withMathJax"
)
)
sd_section("UI Inputs",
"Functions for creating user interface elements that prompt the user for input values or interaction.",
c(
"actionButton",
"checkboxGroupInput",
"checkboxInput",
"dateInput",
"dateRangeInput",
"fileInput",
"numericInput",
"radioButtons",
"selectInput",
"sliderInput",
"submitButton",
"textInput",
"updateCheckboxGroupInput",
"updateCheckboxInput",
"updateDateInput",
"updateDateRangeInput",
"updateNumericInput",
"updateRadioButtons",
"updateSelectInput",
"updateSliderInput",
"updateTabsetPanel",
"updateTextInput"
)
)
sd_section("UI Outputs",
"Functions for creating user interface elements that, in conjunction with rendering functions, display different kinds of output from your application.",
c(
"htmlOutput",
"imageOutput",
"plotOutput",
"outputOptions",
"tableOutput",
"textOutput",
"verbatimTextOutput",
"downloadButton"
)
)
sd_section("Interface builder functions",
"A sub-library for writing HTML using R functions. These functions form the foundation on which the higher level user interface functions are built, and can also be used in your Shiny UI to provide custom HTML, CSS, and JavaScript.",
c(
"builder",
"HTML",
"include",
"singleton",
"tag",
"validateCssUnit",
"withTags"
)
)
sd_section("Rendering functions",
"Functions that you use in your application's server side code, assigning them to outputs that appear in your user interface.",
c(
"renderPlot",
"renderText",
"renderPrint",
"renderDataTable",
"renderImage",
"renderTable",
"renderUI",
"downloadHandler",
"reactivePlot",
"reactivePrint",
"reactiveTable",
"reactiveText",
"reactiveUI"
)
)
sd_section("Reactive constructs",
"A sub-library that provides reactive programming facilities for R.",
c(
"invalidateLater",
"is.reactivevalues",
"isolate",
"makeReactiveBinding",
"observe",
"reactive",
"reactiveFileReader",
"reactivePoll",
"reactiveTimer",
"reactiveValues",
"reactiveValuesToList",
"domains",
"showReactLog"
)
)
sd_section("Boilerplate",
"Functions that are required boilerplate in ui.R and server.R.",
c(
"shinyUI",
"shinyServer"
)
)
sd_section("Running",
"Functions that are used to run or stop Shiny applications.",
c(
"runApp",
"runExample",
"runGist",
"runGitHub",
"runUrl",
"stopApp"
)
)
sd_section("Extending Shiny",
"Functions that are intended to be called by third-party packages that extend Shiny.",
c(
"addResourcePath",
"registerInputHandler",
"removeInputHandler",
"markRenderFunction"
)
)
sd_section("Utility functions",
"Miscellaneous utilities that may be useful to advanced users or when extending Shiny.",
c(
"validate",
"session",
"exprToFunction",
"installExprFunction",
"parseQueryString",
"plotPNG",
"repeatable",
"shinyDeprecated"
)
)
sd_section("Embedding",
"Functions that are intended for third-party packages that embed Shiny applications.",
c(
"shinyApp",
"maskReactiveContext"
)
)

View File

@@ -0,0 +1,95 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Jasmine Spec Runner</title>
<link rel="shortcut icon" type="image/png" href="lib/jasmine-1.3.1/jasmine_favicon.png">
<link rel="stylesheet" type="text/css" href="lib/jasmine-1.3.1/jasmine.css">
<script type="text/javascript" src="lib/jasmine-1.3.1/jasmine.js"></script>
<script type="text/javascript" src="lib/jasmine-1.3.1/jasmine-html.js"></script>
<!-- include source files here... -->
<!-- All of these includes are copied out of the HTML file generated by
shinyUI() -->
<script src="../www/shared/jquery.js" type="text/javascript"></script>
<script src="../www/shared/shiny.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="../www/shared/shiny.css"/>
<link rel="stylesheet" type="text/css" href="../www/shared/slider/css/jquery.slider.min.css"/>
<script src="../www/shared/slider/js/jquery.slider.min.js"></script>
<link rel="stylesheet" type="text/css" href="../www/shared/bootstrap/css/bootstrap.min.css"/>
<script src="../www/shared/bootstrap/js/bootstrap.min.js"></script>
<!-- <meta name="viewport" content="width=device-width, initial-scale=1.0"/> -->
<link rel="stylesheet" type="text/css" href="../www/shared/bootstrap/css/bootstrap-responsive.min.css"/>
<script src="../www/shared/datepicker/js/bootstrap-datepicker.min.js"></script>
<link rel="stylesheet" type="text/css" href="../www/shared/datepicker/css/datepicker.css"/>
<script src="../www/shared/bootstrap-daterangepicker/date.js"></script>
<script src="../www/shared/bootstrap-daterangepicker/daterangepicker.js"></script>
<link rel="stylesheet" type="text/css" href="../www/shared/bootstrap-daterangepicker/daterangepicker.css"/>
<!-- include spec files here... -->
<!-- <script type="text/javascript" src="spec/SpecHelper.js"></script>
<script type="text/javascript" src="spec/PlayerSpec.js"></script>
-->
<script type="text/javascript" src="spec/inputBindingSpec.js"></script>
<script type="text/javascript">
(function() {
var jasmineEnv = jasmine.getEnv();
jasmineEnv.updateInterval = 1000;
var htmlReporter = new jasmine.HtmlReporter();
jasmineEnv.addReporter(htmlReporter);
jasmineEnv.specFilter = function(spec) {
return htmlReporter.specFilter(spec);
};
// var currentWindowOnload = window.onload;
// window.onload = function() {
// if (currentWindowOnload) {
// currentWindowOnload();
// }
// execJasmine();
// };
// Add a slight delay before running tests, so that Shiny has time to
// do setup stuff.
$(document).ready(function() {
setTimeout(function() {
execJasmine();
},
50
)
});
function execJasmine() {
jasmineEnv.execute();
}
})();
// Clear the Shiny disconnected gray screen shortly after loading
$(document).ready(function() {
setTimeout(function() {
$('body').removeClass('disconnected');
},
100
)
});
</script>
</head>
<body>
</body>
</html>

View File

@@ -0,0 +1,2 @@
<label>Text input:</label>
<input id="in_text" type="text" value="starting value"/>

View File

@@ -0,0 +1,20 @@
Copyright (c) 2008-2011 Pivotal Labs
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@@ -0,0 +1,681 @@
jasmine.HtmlReporterHelpers = {};
jasmine.HtmlReporterHelpers.createDom = function(type, attrs, childrenVarArgs) {
var el = document.createElement(type);
for (var i = 2; i < arguments.length; i++) {
var child = arguments[i];
if (typeof child === 'string') {
el.appendChild(document.createTextNode(child));
} else {
if (child) {
el.appendChild(child);
}
}
}
for (var attr in attrs) {
if (attr == "className") {
el[attr] = attrs[attr];
} else {
el.setAttribute(attr, attrs[attr]);
}
}
return el;
};
jasmine.HtmlReporterHelpers.getSpecStatus = function(child) {
var results = child.results();
var status = results.passed() ? 'passed' : 'failed';
if (results.skipped) {
status = 'skipped';
}
return status;
};
jasmine.HtmlReporterHelpers.appendToSummary = function(child, childElement) {
var parentDiv = this.dom.summary;
var parentSuite = (typeof child.parentSuite == 'undefined') ? 'suite' : 'parentSuite';
var parent = child[parentSuite];
if (parent) {
if (typeof this.views.suites[parent.id] == 'undefined') {
this.views.suites[parent.id] = new jasmine.HtmlReporter.SuiteView(parent, this.dom, this.views);
}
parentDiv = this.views.suites[parent.id].element;
}
parentDiv.appendChild(childElement);
};
jasmine.HtmlReporterHelpers.addHelpers = function(ctor) {
for(var fn in jasmine.HtmlReporterHelpers) {
ctor.prototype[fn] = jasmine.HtmlReporterHelpers[fn];
}
};
jasmine.HtmlReporter = function(_doc) {
var self = this;
var doc = _doc || window.document;
var reporterView;
var dom = {};
// Jasmine Reporter Public Interface
self.logRunningSpecs = false;
self.reportRunnerStarting = function(runner) {
var specs = runner.specs() || [];
if (specs.length == 0) {
return;
}
createReporterDom(runner.env.versionString());
doc.body.appendChild(dom.reporter);
setExceptionHandling();
reporterView = new jasmine.HtmlReporter.ReporterView(dom);
reporterView.addSpecs(specs, self.specFilter);
};
self.reportRunnerResults = function(runner) {
reporterView && reporterView.complete();
};
self.reportSuiteResults = function(suite) {
reporterView.suiteComplete(suite);
};
self.reportSpecStarting = function(spec) {
if (self.logRunningSpecs) {
self.log('>> Jasmine Running ' + spec.suite.description + ' ' + spec.description + '...');
}
};
self.reportSpecResults = function(spec) {
reporterView.specComplete(spec);
};
self.log = function() {
var console = jasmine.getGlobal().console;
if (console && console.log) {
if (console.log.apply) {
console.log.apply(console, arguments);
} else {
console.log(arguments); // ie fix: console.log.apply doesn't exist on ie
}
}
};
self.specFilter = function(spec) {
if (!focusedSpecName()) {
return true;
}
return spec.getFullName().indexOf(focusedSpecName()) === 0;
};
return self;
function focusedSpecName() {
var specName;
(function memoizeFocusedSpec() {
if (specName) {
return;
}
var paramMap = [];
var params = jasmine.HtmlReporter.parameters(doc);
for (var i = 0; i < params.length; i++) {
var p = params[i].split('=');
paramMap[decodeURIComponent(p[0])] = decodeURIComponent(p[1]);
}
specName = paramMap.spec;
})();
return specName;
}
function createReporterDom(version) {
dom.reporter = self.createDom('div', { id: 'HTMLReporter', className: 'jasmine_reporter' },
dom.banner = self.createDom('div', { className: 'banner' },
self.createDom('span', { className: 'title' }, "Jasmine "),
self.createDom('span', { className: 'version' }, version)),
dom.symbolSummary = self.createDom('ul', {className: 'symbolSummary'}),
dom.alert = self.createDom('div', {className: 'alert'},
self.createDom('span', { className: 'exceptions' },
self.createDom('label', { className: 'label', 'for': 'no_try_catch' }, 'No try/catch'),
self.createDom('input', { id: 'no_try_catch', type: 'checkbox' }))),
dom.results = self.createDom('div', {className: 'results'},
dom.summary = self.createDom('div', { className: 'summary' }),
dom.details = self.createDom('div', { id: 'details' }))
);
}
function noTryCatch() {
return window.location.search.match(/catch=false/);
}
function searchWithCatch() {
var params = jasmine.HtmlReporter.parameters(window.document);
var removed = false;
var i = 0;
while (!removed && i < params.length) {
if (params[i].match(/catch=/)) {
params.splice(i, 1);
removed = true;
}
i++;
}
if (jasmine.CATCH_EXCEPTIONS) {
params.push("catch=false");
}
return params.join("&");
}
function setExceptionHandling() {
var chxCatch = document.getElementById('no_try_catch');
if (noTryCatch()) {
chxCatch.setAttribute('checked', true);
jasmine.CATCH_EXCEPTIONS = false;
}
chxCatch.onclick = function() {
window.location.search = searchWithCatch();
};
}
};
jasmine.HtmlReporter.parameters = function(doc) {
var paramStr = doc.location.search.substring(1);
var params = [];
if (paramStr.length > 0) {
params = paramStr.split('&');
}
return params;
}
jasmine.HtmlReporter.sectionLink = function(sectionName) {
var link = '?';
var params = [];
if (sectionName) {
params.push('spec=' + encodeURIComponent(sectionName));
}
if (!jasmine.CATCH_EXCEPTIONS) {
params.push("catch=false");
}
if (params.length > 0) {
link += params.join("&");
}
return link;
};
jasmine.HtmlReporterHelpers.addHelpers(jasmine.HtmlReporter);
jasmine.HtmlReporter.ReporterView = function(dom) {
this.startedAt = new Date();
this.runningSpecCount = 0;
this.completeSpecCount = 0;
this.passedCount = 0;
this.failedCount = 0;
this.skippedCount = 0;
this.createResultsMenu = function() {
this.resultsMenu = this.createDom('span', {className: 'resultsMenu bar'},
this.summaryMenuItem = this.createDom('a', {className: 'summaryMenuItem', href: "#"}, '0 specs'),
' | ',
this.detailsMenuItem = this.createDom('a', {className: 'detailsMenuItem', href: "#"}, '0 failing'));
this.summaryMenuItem.onclick = function() {
dom.reporter.className = dom.reporter.className.replace(/ showDetails/g, '');
};
this.detailsMenuItem.onclick = function() {
showDetails();
};
};
this.addSpecs = function(specs, specFilter) {
this.totalSpecCount = specs.length;
this.views = {
specs: {},
suites: {}
};
for (var i = 0; i < specs.length; i++) {
var spec = specs[i];
this.views.specs[spec.id] = new jasmine.HtmlReporter.SpecView(spec, dom, this.views);
if (specFilter(spec)) {
this.runningSpecCount++;
}
}
};
this.specComplete = function(spec) {
this.completeSpecCount++;
if (isUndefined(this.views.specs[spec.id])) {
this.views.specs[spec.id] = new jasmine.HtmlReporter.SpecView(spec, dom);
}
var specView = this.views.specs[spec.id];
switch (specView.status()) {
case 'passed':
this.passedCount++;
break;
case 'failed':
this.failedCount++;
break;
case 'skipped':
this.skippedCount++;
break;
}
specView.refresh();
this.refresh();
};
this.suiteComplete = function(suite) {
var suiteView = this.views.suites[suite.id];
if (isUndefined(suiteView)) {
return;
}
suiteView.refresh();
};
this.refresh = function() {
if (isUndefined(this.resultsMenu)) {
this.createResultsMenu();
}
// currently running UI
if (isUndefined(this.runningAlert)) {
this.runningAlert = this.createDom('a', { href: jasmine.HtmlReporter.sectionLink(), className: "runningAlert bar" });
dom.alert.appendChild(this.runningAlert);
}
this.runningAlert.innerHTML = "Running " + this.completeSpecCount + " of " + specPluralizedFor(this.totalSpecCount);
// skipped specs UI
if (isUndefined(this.skippedAlert)) {
this.skippedAlert = this.createDom('a', { href: jasmine.HtmlReporter.sectionLink(), className: "skippedAlert bar" });
}
this.skippedAlert.innerHTML = "Skipping " + this.skippedCount + " of " + specPluralizedFor(this.totalSpecCount) + " - run all";
if (this.skippedCount === 1 && isDefined(dom.alert)) {
dom.alert.appendChild(this.skippedAlert);
}
// passing specs UI
if (isUndefined(this.passedAlert)) {
this.passedAlert = this.createDom('span', { href: jasmine.HtmlReporter.sectionLink(), className: "passingAlert bar" });
}
this.passedAlert.innerHTML = "Passing " + specPluralizedFor(this.passedCount);
// failing specs UI
if (isUndefined(this.failedAlert)) {
this.failedAlert = this.createDom('span', {href: "?", className: "failingAlert bar"});
}
this.failedAlert.innerHTML = "Failing " + specPluralizedFor(this.failedCount);
if (this.failedCount === 1 && isDefined(dom.alert)) {
dom.alert.appendChild(this.failedAlert);
dom.alert.appendChild(this.resultsMenu);
}
// summary info
this.summaryMenuItem.innerHTML = "" + specPluralizedFor(this.runningSpecCount);
this.detailsMenuItem.innerHTML = "" + this.failedCount + " failing";
};
this.complete = function() {
dom.alert.removeChild(this.runningAlert);
this.skippedAlert.innerHTML = "Ran " + this.runningSpecCount + " of " + specPluralizedFor(this.totalSpecCount) + " - run all";
if (this.failedCount === 0) {
dom.alert.appendChild(this.createDom('span', {className: 'passingAlert bar'}, "Passing " + specPluralizedFor(this.passedCount)));
} else {
showDetails();
}
dom.banner.appendChild(this.createDom('span', {className: 'duration'}, "finished in " + ((new Date().getTime() - this.startedAt.getTime()) / 1000) + "s"));
};
return this;
function showDetails() {
if (dom.reporter.className.search(/showDetails/) === -1) {
dom.reporter.className += " showDetails";
}
}
function isUndefined(obj) {
return typeof obj === 'undefined';
}
function isDefined(obj) {
return !isUndefined(obj);
}
function specPluralizedFor(count) {
var str = count + " spec";
if (count > 1) {
str += "s"
}
return str;
}
};
jasmine.HtmlReporterHelpers.addHelpers(jasmine.HtmlReporter.ReporterView);
jasmine.HtmlReporter.SpecView = function(spec, dom, views) {
this.spec = spec;
this.dom = dom;
this.views = views;
this.symbol = this.createDom('li', { className: 'pending' });
this.dom.symbolSummary.appendChild(this.symbol);
this.summary = this.createDom('div', { className: 'specSummary' },
this.createDom('a', {
className: 'description',
href: jasmine.HtmlReporter.sectionLink(this.spec.getFullName()),
title: this.spec.getFullName()
}, this.spec.description)
);
this.detail = this.createDom('div', { className: 'specDetail' },
this.createDom('a', {
className: 'description',
href: '?spec=' + encodeURIComponent(this.spec.getFullName()),
title: this.spec.getFullName()
}, this.spec.getFullName())
);
};
jasmine.HtmlReporter.SpecView.prototype.status = function() {
return this.getSpecStatus(this.spec);
};
jasmine.HtmlReporter.SpecView.prototype.refresh = function() {
this.symbol.className = this.status();
switch (this.status()) {
case 'skipped':
break;
case 'passed':
this.appendSummaryToSuiteDiv();
break;
case 'failed':
this.appendSummaryToSuiteDiv();
this.appendFailureDetail();
break;
}
};
jasmine.HtmlReporter.SpecView.prototype.appendSummaryToSuiteDiv = function() {
this.summary.className += ' ' + this.status();
this.appendToSummary(this.spec, this.summary);
};
jasmine.HtmlReporter.SpecView.prototype.appendFailureDetail = function() {
this.detail.className += ' ' + this.status();
var resultItems = this.spec.results().getItems();
var messagesDiv = this.createDom('div', { className: 'messages' });
for (var i = 0; i < resultItems.length; i++) {
var result = resultItems[i];
if (result.type == 'log') {
messagesDiv.appendChild(this.createDom('div', {className: 'resultMessage log'}, result.toString()));
} else if (result.type == 'expect' && result.passed && !result.passed()) {
messagesDiv.appendChild(this.createDom('div', {className: 'resultMessage fail'}, result.message));
if (result.trace.stack) {
messagesDiv.appendChild(this.createDom('div', {className: 'stackTrace'}, result.trace.stack));
}
}
}
if (messagesDiv.childNodes.length > 0) {
this.detail.appendChild(messagesDiv);
this.dom.details.appendChild(this.detail);
}
};
jasmine.HtmlReporterHelpers.addHelpers(jasmine.HtmlReporter.SpecView);jasmine.HtmlReporter.SuiteView = function(suite, dom, views) {
this.suite = suite;
this.dom = dom;
this.views = views;
this.element = this.createDom('div', { className: 'suite' },
this.createDom('a', { className: 'description', href: jasmine.HtmlReporter.sectionLink(this.suite.getFullName()) }, this.suite.description)
);
this.appendToSummary(this.suite, this.element);
};
jasmine.HtmlReporter.SuiteView.prototype.status = function() {
return this.getSpecStatus(this.suite);
};
jasmine.HtmlReporter.SuiteView.prototype.refresh = function() {
this.element.className += " " + this.status();
};
jasmine.HtmlReporterHelpers.addHelpers(jasmine.HtmlReporter.SuiteView);
/* @deprecated Use jasmine.HtmlReporter instead
*/
jasmine.TrivialReporter = function(doc) {
this.document = doc || document;
this.suiteDivs = {};
this.logRunningSpecs = false;
};
jasmine.TrivialReporter.prototype.createDom = function(type, attrs, childrenVarArgs) {
var el = document.createElement(type);
for (var i = 2; i < arguments.length; i++) {
var child = arguments[i];
if (typeof child === 'string') {
el.appendChild(document.createTextNode(child));
} else {
if (child) { el.appendChild(child); }
}
}
for (var attr in attrs) {
if (attr == "className") {
el[attr] = attrs[attr];
} else {
el.setAttribute(attr, attrs[attr]);
}
}
return el;
};
jasmine.TrivialReporter.prototype.reportRunnerStarting = function(runner) {
var showPassed, showSkipped;
this.outerDiv = this.createDom('div', { id: 'TrivialReporter', className: 'jasmine_reporter' },
this.createDom('div', { className: 'banner' },
this.createDom('div', { className: 'logo' },
this.createDom('span', { className: 'title' }, "Jasmine"),
this.createDom('span', { className: 'version' }, runner.env.versionString())),
this.createDom('div', { className: 'options' },
"Show ",
showPassed = this.createDom('input', { id: "__jasmine_TrivialReporter_showPassed__", type: 'checkbox' }),
this.createDom('label', { "for": "__jasmine_TrivialReporter_showPassed__" }, " passed "),
showSkipped = this.createDom('input', { id: "__jasmine_TrivialReporter_showSkipped__", type: 'checkbox' }),
this.createDom('label', { "for": "__jasmine_TrivialReporter_showSkipped__" }, " skipped")
)
),
this.runnerDiv = this.createDom('div', { className: 'runner running' },
this.createDom('a', { className: 'run_spec', href: '?' }, "run all"),
this.runnerMessageSpan = this.createDom('span', {}, "Running..."),
this.finishedAtSpan = this.createDom('span', { className: 'finished-at' }, ""))
);
this.document.body.appendChild(this.outerDiv);
var suites = runner.suites();
for (var i = 0; i < suites.length; i++) {
var suite = suites[i];
var suiteDiv = this.createDom('div', { className: 'suite' },
this.createDom('a', { className: 'run_spec', href: '?spec=' + encodeURIComponent(suite.getFullName()) }, "run"),
this.createDom('a', { className: 'description', href: '?spec=' + encodeURIComponent(suite.getFullName()) }, suite.description));
this.suiteDivs[suite.id] = suiteDiv;
var parentDiv = this.outerDiv;
if (suite.parentSuite) {
parentDiv = this.suiteDivs[suite.parentSuite.id];
}
parentDiv.appendChild(suiteDiv);
}
this.startedAt = new Date();
var self = this;
showPassed.onclick = function(evt) {
if (showPassed.checked) {
self.outerDiv.className += ' show-passed';
} else {
self.outerDiv.className = self.outerDiv.className.replace(/ show-passed/, '');
}
};
showSkipped.onclick = function(evt) {
if (showSkipped.checked) {
self.outerDiv.className += ' show-skipped';
} else {
self.outerDiv.className = self.outerDiv.className.replace(/ show-skipped/, '');
}
};
};
jasmine.TrivialReporter.prototype.reportRunnerResults = function(runner) {
var results = runner.results();
var className = (results.failedCount > 0) ? "runner failed" : "runner passed";
this.runnerDiv.setAttribute("class", className);
//do it twice for IE
this.runnerDiv.setAttribute("className", className);
var specs = runner.specs();
var specCount = 0;
for (var i = 0; i < specs.length; i++) {
if (this.specFilter(specs[i])) {
specCount++;
}
}
var message = "" + specCount + " spec" + (specCount == 1 ? "" : "s" ) + ", " + results.failedCount + " failure" + ((results.failedCount == 1) ? "" : "s");
message += " in " + ((new Date().getTime() - this.startedAt.getTime()) / 1000) + "s";
this.runnerMessageSpan.replaceChild(this.createDom('a', { className: 'description', href: '?'}, message), this.runnerMessageSpan.firstChild);
this.finishedAtSpan.appendChild(document.createTextNode("Finished at " + new Date().toString()));
};
jasmine.TrivialReporter.prototype.reportSuiteResults = function(suite) {
var results = suite.results();
var status = results.passed() ? 'passed' : 'failed';
if (results.totalCount === 0) { // todo: change this to check results.skipped
status = 'skipped';
}
this.suiteDivs[suite.id].className += " " + status;
};
jasmine.TrivialReporter.prototype.reportSpecStarting = function(spec) {
if (this.logRunningSpecs) {
this.log('>> Jasmine Running ' + spec.suite.description + ' ' + spec.description + '...');
}
};
jasmine.TrivialReporter.prototype.reportSpecResults = function(spec) {
var results = spec.results();
var status = results.passed() ? 'passed' : 'failed';
if (results.skipped) {
status = 'skipped';
}
var specDiv = this.createDom('div', { className: 'spec ' + status },
this.createDom('a', { className: 'run_spec', href: '?spec=' + encodeURIComponent(spec.getFullName()) }, "run"),
this.createDom('a', {
className: 'description',
href: '?spec=' + encodeURIComponent(spec.getFullName()),
title: spec.getFullName()
}, spec.description));
var resultItems = results.getItems();
var messagesDiv = this.createDom('div', { className: 'messages' });
for (var i = 0; i < resultItems.length; i++) {
var result = resultItems[i];
if (result.type == 'log') {
messagesDiv.appendChild(this.createDom('div', {className: 'resultMessage log'}, result.toString()));
} else if (result.type == 'expect' && result.passed && !result.passed()) {
messagesDiv.appendChild(this.createDom('div', {className: 'resultMessage fail'}, result.message));
if (result.trace.stack) {
messagesDiv.appendChild(this.createDom('div', {className: 'stackTrace'}, result.trace.stack));
}
}
}
if (messagesDiv.childNodes.length > 0) {
specDiv.appendChild(messagesDiv);
}
this.suiteDivs[spec.suite.id].appendChild(specDiv);
};
jasmine.TrivialReporter.prototype.log = function() {
var console = jasmine.getGlobal().console;
if (console && console.log) {
if (console.log.apply) {
console.log.apply(console, arguments);
} else {
console.log(arguments); // ie fix: console.log.apply doesn't exist on ie
}
}
};
jasmine.TrivialReporter.prototype.getLocation = function() {
return this.document.location;
};
jasmine.TrivialReporter.prototype.specFilter = function(spec) {
var paramMap = {};
var params = this.getLocation().search.substring(1).split('&');
for (var i = 0; i < params.length; i++) {
var p = params[i].split('=');
paramMap[decodeURIComponent(p[0])] = decodeURIComponent(p[1]);
}
if (!paramMap.spec) {
return true;
}
return spec.getFullName().indexOf(paramMap.spec) === 0;
};

View File

@@ -0,0 +1,82 @@
body { background-color: #eeeeee; padding: 0; margin: 5px; overflow-y: scroll; }
#HTMLReporter { font-size: 11px; font-family: Monaco, "Lucida Console", monospace; line-height: 14px; color: #333333; }
#HTMLReporter a { text-decoration: none; }
#HTMLReporter a:hover { text-decoration: underline; }
#HTMLReporter p, #HTMLReporter h1, #HTMLReporter h2, #HTMLReporter h3, #HTMLReporter h4, #HTMLReporter h5, #HTMLReporter h6 { margin: 0; line-height: 14px; }
#HTMLReporter .banner, #HTMLReporter .symbolSummary, #HTMLReporter .summary, #HTMLReporter .resultMessage, #HTMLReporter .specDetail .description, #HTMLReporter .alert .bar, #HTMLReporter .stackTrace { padding-left: 9px; padding-right: 9px; }
#HTMLReporter #jasmine_content { position: fixed; right: 100%; }
#HTMLReporter .version { color: #aaaaaa; }
#HTMLReporter .banner { margin-top: 14px; }
#HTMLReporter .duration { color: #aaaaaa; float: right; }
#HTMLReporter .symbolSummary { overflow: hidden; *zoom: 1; margin: 14px 0; }
#HTMLReporter .symbolSummary li { display: block; float: left; height: 7px; width: 14px; margin-bottom: 7px; font-size: 16px; }
#HTMLReporter .symbolSummary li.passed { font-size: 14px; }
#HTMLReporter .symbolSummary li.passed:before { color: #5e7d00; content: "\02022"; }
#HTMLReporter .symbolSummary li.failed { line-height: 9px; }
#HTMLReporter .symbolSummary li.failed:before { color: #b03911; content: "x"; font-weight: bold; margin-left: -1px; }
#HTMLReporter .symbolSummary li.skipped { font-size: 14px; }
#HTMLReporter .symbolSummary li.skipped:before { color: #bababa; content: "\02022"; }
#HTMLReporter .symbolSummary li.pending { line-height: 11px; }
#HTMLReporter .symbolSummary li.pending:before { color: #aaaaaa; content: "-"; }
#HTMLReporter .exceptions { color: #fff; float: right; margin-top: 5px; margin-right: 5px; }
#HTMLReporter .bar { line-height: 28px; font-size: 14px; display: block; color: #eee; }
#HTMLReporter .runningAlert { background-color: #666666; }
#HTMLReporter .skippedAlert { background-color: #aaaaaa; }
#HTMLReporter .skippedAlert:first-child { background-color: #333333; }
#HTMLReporter .skippedAlert:hover { text-decoration: none; color: white; text-decoration: underline; }
#HTMLReporter .passingAlert { background-color: #a6b779; }
#HTMLReporter .passingAlert:first-child { background-color: #5e7d00; }
#HTMLReporter .failingAlert { background-color: #cf867e; }
#HTMLReporter .failingAlert:first-child { background-color: #b03911; }
#HTMLReporter .results { margin-top: 14px; }
#HTMLReporter #details { display: none; }
#HTMLReporter .resultsMenu, #HTMLReporter .resultsMenu a { background-color: #fff; color: #333333; }
#HTMLReporter.showDetails .summaryMenuItem { font-weight: normal; text-decoration: inherit; }
#HTMLReporter.showDetails .summaryMenuItem:hover { text-decoration: underline; }
#HTMLReporter.showDetails .detailsMenuItem { font-weight: bold; text-decoration: underline; }
#HTMLReporter.showDetails .summary { display: none; }
#HTMLReporter.showDetails #details { display: block; }
#HTMLReporter .summaryMenuItem { font-weight: bold; text-decoration: underline; }
#HTMLReporter .summary { margin-top: 14px; }
#HTMLReporter .summary .suite .suite, #HTMLReporter .summary .specSummary { margin-left: 14px; }
#HTMLReporter .summary .specSummary.passed a { color: #5e7d00; }
#HTMLReporter .summary .specSummary.failed a { color: #b03911; }
#HTMLReporter .description + .suite { margin-top: 0; }
#HTMLReporter .suite { margin-top: 14px; }
#HTMLReporter .suite a { color: #333333; }
#HTMLReporter #details .specDetail { margin-bottom: 28px; }
#HTMLReporter #details .specDetail .description { display: block; color: white; background-color: #b03911; }
#HTMLReporter .resultMessage { padding-top: 14px; color: #333333; }
#HTMLReporter .resultMessage span.result { display: block; }
#HTMLReporter .stackTrace { margin: 5px 0 0 0; max-height: 224px; overflow: auto; line-height: 18px; color: #666666; border: 1px solid #ddd; background: white; white-space: pre; }
#TrivialReporter { padding: 8px 13px; position: absolute; top: 0; bottom: 0; left: 0; right: 0; overflow-y: scroll; background-color: white; font-family: "Helvetica Neue Light", "Lucida Grande", "Calibri", "Arial", sans-serif; /*.resultMessage {*/ /*white-space: pre;*/ /*}*/ }
#TrivialReporter a:visited, #TrivialReporter a { color: #303; }
#TrivialReporter a:hover, #TrivialReporter a:active { color: blue; }
#TrivialReporter .run_spec { float: right; padding-right: 5px; font-size: .8em; text-decoration: none; }
#TrivialReporter .banner { color: #303; background-color: #fef; padding: 5px; }
#TrivialReporter .logo { float: left; font-size: 1.1em; padding-left: 5px; }
#TrivialReporter .logo .version { font-size: .6em; padding-left: 1em; }
#TrivialReporter .runner.running { background-color: yellow; }
#TrivialReporter .options { text-align: right; font-size: .8em; }
#TrivialReporter .suite { border: 1px outset gray; margin: 5px 0; padding-left: 1em; }
#TrivialReporter .suite .suite { margin: 5px; }
#TrivialReporter .suite.passed { background-color: #dfd; }
#TrivialReporter .suite.failed { background-color: #fdd; }
#TrivialReporter .spec { margin: 5px; padding-left: 1em; clear: both; }
#TrivialReporter .spec.failed, #TrivialReporter .spec.passed, #TrivialReporter .spec.skipped { padding-bottom: 5px; border: 1px solid gray; }
#TrivialReporter .spec.failed { background-color: #fbb; border-color: red; }
#TrivialReporter .spec.passed { background-color: #bfb; border-color: green; }
#TrivialReporter .spec.skipped { background-color: #bbb; }
#TrivialReporter .messages { border-left: 1px dashed gray; padding-left: 1em; padding-right: 1em; }
#TrivialReporter .passed { background-color: #cfc; display: none; }
#TrivialReporter .failed { background-color: #fbb; }
#TrivialReporter .skipped { color: #777; background-color: #eee; display: none; }
#TrivialReporter .resultMessage span.result { display: block; line-height: 2em; color: black; }
#TrivialReporter .resultMessage .mismatch { color: black; }
#TrivialReporter .stackTrace { white-space: pre; font-size: .8em; margin-left: 10px; max-height: 5em; overflow: auto; border: 1px inset red; padding: 1em; background: #eef; }
#TrivialReporter .finished-at { padding-left: 1em; font-size: .6em; }
#TrivialReporter.show-passed .passed, #TrivialReporter.show-skipped .skipped { display: block; }
#TrivialReporter #jasmine_content { position: fixed; right: 100%; }
#TrivialReporter .runner { border: 1px solid gray; display: block; margin: 5px 0; padding: 2px 0 2px 10px; }

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,45 @@
context("bootstrap")
test_that("CSS unit validation", {
# On error, return NA; on success, return result
validateCssUnit_wrap <- function(x) {
tryCatch(validateCssUnit(x), error = function(e) { NA_character_ })
}
# Test strings and expected results
strings <- c("100x", "10px", "10.4px", ".4px", "1px0", "px", "5", "%", "5%", "auto", "1auto", "")
expected <- c(NA, "10px", "10.4px", ".4px", NA, NA, "5px", NA, "5%", "auto", NA, NA)
results <- vapply(strings, validateCssUnit_wrap, character(1), USE.NAMES = FALSE)
expect_equal(results, expected)
# Numbers should return string with "px"
expect_equal(validateCssUnit(100), "100px")
})
test_that("Repeated names for selectInput and radioButtons choices", {
# These test might be a bit too closely tied to the exact structure of the
# tag object, but they get the job done for now.
# Select input
x <- selectInput('id','label', choices = c(a='x1', a='x2', b='x3'), selectize = FALSE)
expect_equal(format(x), '<label class="control-label" for="id">label</label>
<select id="id"><option value="x1" selected>a</option>\n<option value="x2">a</option>\n<option value="x3">b</option></select>')
# Radio buttons
x <- radioButtons('id','label', choices = c(a='x1', a='x2', b='x3'))
choices <- x$children
expect_equal(choices[[2]][[1]]$children[[2]]$children[[1]], 'a')
expect_equal(choices[[2]][[1]]$children[[1]]$attribs$value, 'x1')
expect_equal(choices[[2]][[1]]$children[[1]]$attribs$checked, 'checked')
expect_equal(choices[[2]][[2]]$children[[2]]$children[[1]], 'a')
expect_equal(choices[[2]][[2]]$children[[1]]$attribs$value, 'x2')
expect_equal(choices[[2]][[2]]$children[[1]]$attribs$checked, NULL)
expect_equal(choices[[2]][[3]]$children[[2]]$children[[1]], 'b')
expect_equal(choices[[2]][[3]]$children[[1]]$attribs$value, 'x3')
expect_equal(choices[[2]][[3]]$children[[1]]$attribs$checked, NULL)
})

73
inst/tests/test-gc.r Normal file
View File

@@ -0,0 +1,73 @@
context("garbage collection")
test_that("unreferenced observers are garbage collected", {
vals_removed <- FALSE
obs_removed <- FALSE
vals <- reactiveValues(A=1)
obs <- observe({ vals$A })
# These are called when the objects are garbage-collected
reg.finalizer(attr(.subset2(vals,'impl'), ".xData"),
function(e) vals_removed <<- TRUE)
reg.finalizer(attr(obs, ".xData"),
function(e) obs_removed <<- TRUE)
flushReact()
# Removing this reference to obs doesn't delete it because vals still has a
# reference to it
rm(obs)
invisible(gc())
expect_equal(c(vals_removed, obs_removed), c(FALSE, FALSE))
# Updating vals$A and flushing won't make obs go away because it creates a new
# context, and vals$A's context tracks obs's context as a dependent
vals$A <- 2
flushReact()
invisible(gc())
expect_equal(c(vals_removed, obs_removed), c(FALSE, FALSE))
# Removing vals will result in vals and obs being garbage collected since
# there are no other references to them
rm(vals)
invisible(gc())
expect_equal(c(vals_removed, obs_removed), c(TRUE, TRUE))
})
test_that("suspended observers are garbage collected", {
vals_removed <- FALSE
obs_removed <- FALSE
vals <- reactiveValues(A=1)
obs <- observe({ vals$A })
# These are called when the objects are garbage-collected
reg.finalizer(attr(.subset2(vals,'impl'), ".xData"),
function(e) vals_removed <<- TRUE)
reg.finalizer(attr(obs, ".xData"),
function(e) obs_removed <<- TRUE)
flushReact()
vals$A <- 2
flushReact()
invisible(gc())
# Simply suspending and removing our reference to obs doesn't result in GC,
# because vals's context still has a reference to obs's context, as a dependent
obs$suspend()
rm(obs)
invisible(gc())
expect_equal(c(vals_removed, obs_removed), c(FALSE, FALSE))
# Next time we update vals$A and flush, there's no more reference to obs
vals$A <- 3
flushReact()
invisible(gc())
expect_equal(c(vals_removed, obs_removed), c(FALSE, TRUE))
# Deleting vals should work immediately now
rm(vals)
invisible(gc()) # Removes vals object
expect_equal(c(vals_removed, obs_removed), c(TRUE, TRUE))
})

Some files were not shown because too many files have changed in this diff Show More