Skip to content

Commit f0237cd

Browse files
committedMay 23, 2017
Tidied up function that launches the Shiny app. Dependencies are in suggests, and are installed only when needed.
1 parent 779f842 commit f0237cd

8 files changed

+82
-23
lines changed
 

‎DESCRIPTION

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Package: SqlRender
22
Type: Package
33
Title: Rendering Parameterized SQL and Translation to Dialects
4-
Version: 1.3.7
5-
Date: 2017-05-03
4+
Version: 1.4.0
5+
Date: 2017-05-23
66
Author: Martijn J. Schuemie [aut, cre],
77
Marc A. Suchard [aut],
88
Maintainer: Martijn Schuemie <schuemie@ohdsi.org>
@@ -14,11 +14,12 @@ VignetteBuilder: knitr
1414
URL: https://github.com/OHDSI/SqlRender
1515
BugReports: https://github.com/OHDSI/SqlRender/issues
1616
Imports:
17-
rJava,
18-
shiny
17+
rJava
1918
Suggests:
2019
testthat,
2120
knitr,
22-
rmarkdown
21+
rmarkdown,
22+
shiny,
23+
shinydashboard
2324
LazyData: false
2425
RoxygenNote: 6.0.1

‎NAMESPACE

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
export(camelCaseToSnakeCase)
44
export(createRWrapperForSql)
5-
export(launchSqlDeveloper)
5+
export(launchSqlRenderDeveloper)
66
export(loadRenderTranslateSql)
77
export(readSql)
88
export(renderSql)
@@ -13,3 +13,5 @@ export(translateSql)
1313
export(translateSqlFile)
1414
export(writeSql)
1515
import(rJava)
16+
importFrom(utils,install.packages)
17+
importFrom(utils,menu)

‎R/RenderSql.R

+7
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@
2020
# @author Martijn Schuemie
2121
# @author Marc Suchard
2222

23+
#' SqlRender
24+
#'
25+
#' @docType package
26+
#' @name SqlRender
27+
#' @importFrom utils install.packages menu
28+
NULL
29+
2330
.onLoad <- function(libname, pkgname) {
2431
rJava::.jpackage(pkgname, lib.loc = libname)
2532
}

‎R/ShinyApps.R

+31-3
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,41 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17-
#' Launch the SQL Developer Shiny app
17+
#' Launch the SqlRender Developer Shiny app
18+
#'
19+
#' @param launch.browser Should the app be launched in your default browser, or in a Shiny window.
20+
#' Note: copying to clipboard will not work in a Shiny window.
1821
#'
1922
#' @details
2023
#' Launches a Shiny app that allows the user to develop SQL and see how it translates to the supported dialects.
2124
#'
2225
#' @export
23-
launchSqlDeveloper <- function() {
26+
launchSqlRenderDeveloper <- function(launch.browser = TRUE) {
27+
ensure_installed("shinydashboard")
2428
appDir <- system.file("shinyApps", "SqlDeveloper", package = "SqlRender")
25-
shiny::runApp(appDir, display.mode = "normal")
29+
shiny::runApp(appDir, display.mode = "normal", launch.browser = launch.browser)
30+
}
31+
32+
# Borrowed from devtools: https://github.com/hadley/devtools/blob/ba7a5a4abd8258c52cb156e7b26bb4bf47a79f0b/R/utils.r#L44
33+
is_installed <- function (pkg, version = 0) {
34+
installed_version <- tryCatch(utils::packageVersion(pkg),
35+
error = function(e) NA)
36+
!is.na(installed_version) && installed_version >= version
37+
}
38+
39+
# Borrowed and adapted from devtools: https://github.com/hadley/devtools/blob/ba7a5a4abd8258c52cb156e7b26bb4bf47a79f0b/R/utils.r#L74
40+
ensure_installed <- function(pkg) {
41+
if (!is_installed(pkg)) {
42+
msg <- paste0(sQuote(pkg), " must be installed for this functionality.")
43+
if (interactive()) {
44+
message(msg, "\nWould you like to install it?")
45+
if (menu(c("Yes", "No")) == 1) {
46+
install.packages(pkg)
47+
} else {
48+
stop(msg, call. = FALSE)
49+
}
50+
} else {
51+
stop(msg, call. = FALSE)
52+
}
53+
}
2654
}

‎README.md

+7
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,13 @@ library(devtools)
7373
install_github("ohdsi/SqlRender")
7474
```
7575

76+
Once installed, you can try out SqlRender in a Shiny app that comes with the package:
77+
78+
```r
79+
library(SqlRender)
80+
launchSqlRenderDeveloper()
81+
```
82+
7683
## Java library
7784
You can fetch the JAR file in the inst/java folder of this repository, or use Maven:
7885

‎man/SqlRender.Rd

+10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎man/launchSqlDeveloper.Rd

-14
This file was deleted.

‎man/launchSqlRenderDeveloper.Rd

+18
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
Please sign in to comment.