Compare commits

..

12 Commits

Author SHA1 Message Date
Carson
cc13ba80cc Handle a user-supplied NULL/NA for port 2019-09-12 11:00:05 -05:00
Carson
bb3f324b56 findPort() instead of randomPort() 2019-09-12 10:47:05 -05:00
Carson
84d53e57e4 staticdocs entry 2019-09-11 16:46:05 -05:00
Carson
f8d048a742 Resolve the host before finding the port 2019-09-11 14:34:06 -05:00
Carson
0697dc2b72 more cleanup 2019-09-11 14:26:35 -05:00
Carson
55349d7770 clean-up docs 2019-09-11 14:24:16 -05:00
Carson
2c753fae8f Export randomPort(). Closes #2562 2019-09-11 14:20:21 -05:00
Carson Sievert
b889b0d2b0 Merge pull request #2582 from rstudio/barret_showcase_hidden_wide
Fix showcase bug where hidden by default on wide window
2019-09-11 10:59:18 -07:00
Carson
ba5733e4a4 add news item 2019-09-11 12:34:20 -05:00
Barret Schloerke
c0a7a6d0d6 don't hide the current element, instead make sure new element is hidden before fading in 2019-09-04 12:44:08 -04:00
Barret Schloerke
29c48471f2 hide the prior element, not the new element 2019-09-04 12:24:49 -04:00
Barret Schloerke
229e56464b if no code tab exists, do not attempt to highlight it 2019-09-04 12:24:20 -04:00
12 changed files with 163 additions and 107 deletions

View File

@@ -84,6 +84,7 @@ export(fileInput)
export(fillCol)
export(fillPage)
export(fillRow)
export(findPort)
export(fixedPage)
export(fixedPanel)
export(fixedRow)

View File

@@ -52,6 +52,8 @@ shiny 1.3.2.9001
* Fixed [rstudio/reactlog#36](https://github.com/rstudio/reactlog/issues/36): Changes to reactive values not displaying accurately in reactlog. ([#2424](https://github.com/rstudio/shiny/pull/2424))
* Fixed [#2598](https://github.com/rstudio/shiny/issues/2598): Showcase files don't appear with a wide window. ([#2582](https://github.com/rstudio/shiny/pull/2582))
* Fixed [#2329](https://github.com/rstudio/shiny/issues/2329), [#1817](https://github.com/rstudio/shiny/issues/1817): These bugs were reported as fixed in Shiny 1.3.0 but were not actually fixed because some JavaScript changes were accidentally not included in the release. The fix resolves issues that occur when `withProgressBar()` or bookmarking are combined with the [networkD3](https://christophergandrud.github.io/networkD3/) package's Sankey plot.
### Library updates

View File

@@ -45,47 +45,3 @@ headerPanel <- function(title, windowTitle=title) {
)
)
}
#' Create a Bootstrap page
#'
#' **DEPRECATED**: use [fluidPage()] instead.
#'
#' @param ... The contents of the document body.
#' @param title The browser window title (defaults to the host URL of the page)
#' @param responsive This option is deprecated; it is no longer optional with
#' Bootstrap 3.
#' @param theme Alternative Bootstrap stylesheet (normally a css file within the
#' www directory, e.g. `www/bootstrap.css`)
#'
#' @return A UI defintion that can be passed to the [shinyUI] function.
#'
#' @keywords internal
#' @seealso [fluidPage()], [fixedPage()]
#' @export
bootstrapPage <- function(..., title = NULL, responsive = NULL, theme = NULL) {
if (!is.null(responsive)) {
shinyDeprecated("The 'responsive' argument is no longer used with Bootstrap 3.")
}
attachDependencies(
tagList(
if (!is.null(title)) tags$head(tags$title(title)),
if (!is.null(theme)) {
tags$head(tags$link(rel="stylesheet", type="text/css", href = theme))
},
# remainder of tags passed to the function
list(...)
),
bootstrapLib()
)
}
#' @rdname bootstrapPage
#' @export
basicPage <- function(...) {
bootstrapPage(div(class="container-fluid", list(...)))
}

View File

@@ -1,6 +1,51 @@
#' @include utils.R
NULL
#' Create a Bootstrap page
#'
#' Create a Shiny UI page that loads the CSS and JavaScript for
#' [Bootstrap](http://getbootstrap.com/), and has no content in the page
#' body (other than what you provide).
#'
#' This function is primarily intended for users who are proficient in HTML/CSS,
#' and know how to lay out pages in Bootstrap. Most applications should use
#' [fluidPage()] along with layout functions like
#' [fluidRow()] and [sidebarLayout()].
#'
#' @param ... The contents of the document body.
#' @param title The browser window title (defaults to the host URL of the page)
#' @param responsive This option is deprecated; it is no longer optional with
#' Bootstrap 3.
#' @param theme Alternative Bootstrap stylesheet (normally a css file within the
#' www directory, e.g. `www/bootstrap.css`)
#'
#' @return A UI defintion that can be passed to the [shinyUI] function.
#'
#' @note The `basicPage` function is deprecated, you should use the
#' [fluidPage()] function instead.
#'
#' @seealso [fluidPage()], [fixedPage()]
#' @export
bootstrapPage <- function(..., title = NULL, responsive = NULL, theme = NULL) {
if (!is.null(responsive)) {
shinyDeprecated("The 'responsive' argument is no longer used with Bootstrap 3.")
}
attachDependencies(
tagList(
if (!is.null(title)) tags$head(tags$title(title)),
if (!is.null(theme)) {
tags$head(tags$link(rel="stylesheet", type="text/css", href = theme))
},
# remainder of tags passed to the function
list(...)
),
bootstrapLib()
)
}
#' Bootstrap libraries
#'
#' This function returns a set of web dependencies necessary for using Bootstrap
@@ -31,6 +76,12 @@ bootstrapLib <- function(theme = NULL) {
)
}
#' @rdname bootstrapPage
#' @export
basicPage <- function(...) {
bootstrapPage(div(class="container-fluid", list(...)))
}
#' Create a page that fills the window
#'

View File

@@ -724,7 +724,7 @@ isRunning <- function() {
#' }
#' @export
runApp <- function(appDir=getwd(),
port=getOption('shiny.port'),
port=getOption('shiny.port', findPort(host = host)),
launch.browser=getOption('shiny.launch.browser',
interactive()),
host=getOption('shiny.host', '127.0.0.1'),
@@ -794,12 +794,12 @@ runApp <- function(appDir=getwd(),
if (arg %in% names(appOps)) appOps[[arg]] else default
}
if (missing(host))
host <- findVal("host", host %OR% '0.0.0.0')
if (missing(port))
port <- findVal("port", port)
port <- findVal("port", port %OR% findPort(host = host))
if (missing(launch.browser))
launch.browser <- findVal("launch.browser", launch.browser)
if (missing(host))
host <- findVal("host", host)
if (missing(quiet))
quiet <- findVal("quiet", quiet)
if (missing(display.mode))
@@ -807,8 +807,6 @@ runApp <- function(appDir=getwd(),
if (missing(test.mode))
test.mode <- findVal("test.mode", test.mode)
if (is.null(host) || is.na(host)) host <- '0.0.0.0'
workerId(workerId)
if (inShinyServer()) {
@@ -883,44 +881,6 @@ runApp <- function(appDir=getwd(),
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
while (TRUE) {
port <- p_randomInt(3000, 8000)
# Reject ports in this range that are considered unsafe by Chrome
# http://superuser.com/questions/188058/which-ports-are-considered-unsafe-on-chrome
# https://github.com/rstudio/shiny/issues/1784
if (!port %in% c(3659, 4045, 6000, 6665:6669, 6697)) {
break
}
}
}
# 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
}
}
}
# Invoke user-defined onStop callbacks, before the application's internal
# onStop callbacks.
on.exit({
@@ -1062,7 +1022,7 @@ stopApp <- function(returnValue = invisible()) {
#' }
#' @export
runExample <- function(example=NA,
port=NULL,
port=getOption('shiny.port', findPort(host = host)),
launch.browser=getOption('shiny.launch.browser',
interactive()),
host=getOption('shiny.host', '127.0.0.1'),
@@ -1126,7 +1086,7 @@ runExample <- function(example=NA,
#' runGadget(shinyApp(ui, server))
#' }
#' @export
runGadget <- function(app, server = NULL, port = getOption("shiny.port"),
runGadget <- function(app, server = NULL, port = getOption("shiny.port", findPort()),
viewer = paneViewer(), stopOnCancel = TRUE) {
if (!is.shiny.appobj(app)) {
@@ -1221,6 +1181,41 @@ browserViewer <- function(browser = getOption("browser")) {
}
}
#' Find an open TCP port
#'
#' Finds a random available TCP port for listening on.
#'
#' @param min Minimum port number.
#' @param max Maximum port number.
#' @param host see [httpuv::randomPort()].
#' @param n Number of ports to try before giving up.
#' @param cache if `TRUE`, use the last random port if it's available.
#'
#' @details This function automatically excludes some ports
#' which are considered unsafe by web browsers.
#'
#' @seealso [httpuv::randomPort()]
#' @export
#' @examples
#'
#' findPort()
#' findPort()
#' findPort(cache = FALSE)
findPort <- function(min = 3000L, max = 8000L,
host = getOption("shiny.host", "127.0.0.1"),
n = 20, cache = TRUE) {
if (cache && !is.null(.globals$lastPort)) {
tmp <- try(startServer(host, .globals$lastPort, list()), silent = TRUE)
if (!inherits(tmp, 'try-error')) {
stopServer(tmp)
return(.globals$lastPort)
}
}
.globals$lastPort <- withPrivateSeed(httpuv::randomPort(min, max, host, n))
.globals$lastPort
}
# Returns TRUE if we're running in Shiny Server or other hosting environment,
# otherwise returns FALSE.
inShinyServer <- function() {

View File

@@ -204,7 +204,8 @@ sd_section("Utility functions",
"onStop",
"diskCache",
"memoryCache",
"reexports"
"reexports",
"findPort"
)
)
sd_section("Plot interaction",

View File

@@ -83,6 +83,8 @@
el.id = "srcref_" + srcref;
var ref = srcref;
var code = document.getElementById(srcfile.replace(/\./g, "_") + "_code");
// if there is no code file (might be a shiny file), quit early
if (!code) return;
var start = findTextPoint(code, ref[0], ref[4]);
var end = findTextPoint(code, ref[2], ref[5]);
@@ -148,6 +150,8 @@
}
}
// hide the new element before doing anything to it
$(newHostElement).hide();
$(currentHostElement).fadeOut(animateCodeMs, function() {
var tabs = document.getElementById("showcase-code-tabs");
currentHostElement.removeChild(tabs);
@@ -160,7 +164,7 @@
document.getElementById("showcase-code-content").removeAttribute("style");
}
$(newHostElement).fadeIn();
$(newHostElement).fadeIn(animateCodeMs);
if (!above) {
// remove the applied width and zoom on the app container, and
// scroll smoothly down to the code's new home
@@ -189,7 +193,6 @@
if (above) {
$(document.body).animate({ scrollTop: 0 }, animateCodeMs);
}
$(newHostElement).hide();
isCodeAbove = above;
setAppCodeSxsWidths(above && animate);
$(window).trigger("resize");

View File

@@ -1,5 +1,5 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/bootstrap-deprecated.R
% Please edit documentation in R/bootstrap.R
\name{bootstrapPage}
\alias{bootstrapPage}
\alias{basicPage}
@@ -24,9 +24,20 @@ www directory, e.g. \code{www/bootstrap.css})}
A UI defintion that can be passed to the \link{shinyUI} function.
}
\description{
\strong{DEPRECATED}: use \code{\link[=fluidPage]{fluidPage()}} instead.
Create a Shiny UI page that loads the CSS and JavaScript for
\href{http://getbootstrap.com/}{Bootstrap}, and has no content in the page
body (other than what you provide).
}
\details{
This function is primarily intended for users who are proficient in HTML/CSS,
and know how to lay out pages in Bootstrap. Most applications should use
\code{\link[=fluidPage]{fluidPage()}} along with layout functions like
\code{\link[=fluidRow]{fluidRow()}} and \code{\link[=sidebarLayout]{sidebarLayout()}}.
}
\note{
The \code{basicPage} function is deprecated, you should use the
\code{\link[=fluidPage]{fluidPage()}} function instead.
}
\seealso{
\code{\link[=fluidPage]{fluidPage()}}, \code{\link[=fixedPage]{fixedPage()}}
}
\keyword{internal}

36
man/findPort.Rd Normal file
View File

@@ -0,0 +1,36 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/server.R
\name{findPort}
\alias{findPort}
\title{Find an open TCP port}
\usage{
findPort(min = 3000L, max = 8000L, host = getOption("shiny.host",
"127.0.0.1"), n = 20, cache = TRUE)
}
\arguments{
\item{min}{Minimum port number.}
\item{max}{Maximum port number.}
\item{host}{see \code{\link[httpuv:randomPort]{httpuv::randomPort()}}.}
\item{n}{Number of ports to try before giving up.}
\item{cache}{if \code{TRUE}, use the last random port if it's available.}
}
\description{
Finds a random available TCP port for listening on.
}
\details{
This function automatically excludes some ports
which are considered unsafe by web browsers.
}
\examples{
findPort()
findPort()
findPort(cache = FALSE)
}
\seealso{
\code{\link[httpuv:randomPort]{httpuv::randomPort()}}
}

View File

@@ -4,11 +4,11 @@
\alias{runApp}
\title{Run Shiny Application}
\usage{
runApp(appDir = getwd(), port = getOption("shiny.port"),
launch.browser = getOption("shiny.launch.browser", interactive()),
host = getOption("shiny.host", "127.0.0.1"), workerId = "",
quiet = FALSE, display.mode = c("auto", "normal", "showcase"),
test.mode = getOption("shiny.testmode", FALSE))
runApp(appDir = getwd(), port = getOption("shiny.port", findPort(host =
host)), launch.browser = getOption("shiny.launch.browser",
interactive()), host = getOption("shiny.host", "127.0.0.1"),
workerId = "", quiet = FALSE, display.mode = c("auto", "normal",
"showcase"), test.mode = getOption("shiny.testmode", FALSE))
}
\arguments{
\item{appDir}{The application to run. Should be one of the following:

View File

@@ -4,10 +4,10 @@
\alias{runExample}
\title{Run Shiny Example Applications}
\usage{
runExample(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"))
runExample(example = NA, port = getOption("shiny.port", findPort(host =
host)), launch.browser = getOption("shiny.launch.browser",
interactive()), host = getOption("shiny.host", "127.0.0.1"),
display.mode = c("auto", "normal", "showcase"))
}
\arguments{
\item{example}{The name of the example to run, or \code{NA} (the default) to

View File

@@ -4,8 +4,8 @@
\alias{runGadget}
\title{Run a gadget}
\usage{
runGadget(app, server = NULL, port = getOption("shiny.port"),
viewer = paneViewer(), stopOnCancel = TRUE)
runGadget(app, server = NULL, port = getOption("shiny.port",
findPort()), viewer = paneViewer(), stopOnCancel = TRUE)
}
\arguments{
\item{app}{Either a Shiny app object as created by