Browse Source

super alpha release

master
boB Rudis 4 years ago
parent
commit
eb53befa6b
No known key found for this signature in database GPG Key ID: 1D7529BE14E2BBA9
  1. 5
      DESCRIPTION
  2. 6
      NAMESPACE
  3. 14
      R/grandview-app.R
  4. 3
      R/grandview-package.R
  5. 45
      R/hgd.R
  6. 48
      R/install-viewer.R
  7. 22
      R/zzz.R
  8. 26
      README.Rmd
  9. 116
      README.md
  10. 9
      man/hgd.Rd
  11. 11
      man/install_viewer.Rd
  12. 8
      tools-raw/gdview.go

5
DESCRIPTION

@ -21,7 +21,10 @@ Depends:
R (>= 4.0.0)
Imports:
httpgd,
tools
tools,
utils,
httr,
jsonlite
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.1.0
Remotes:

6
NAMESPACE

@ -1,5 +1,11 @@
# Generated by roxygen2: do not edit by hand
export(hgd)
export(install_viewer)
importFrom(httpgd,httpgd)
importFrom(httr,GET)
importFrom(httr,progress)
importFrom(httr,write_disk)
importFrom(jsonlite,fromJSON)
importFrom(tools,R_user_dir)
importFrom(utils,unzip)

14
R/grandview-app.R

@ -13,7 +13,19 @@ is_macos <- function() {
grandview_app <- function() {
if (is_macos()) {
file.path(tools::R_user_dir(package = "grandview"), "app", "GrandView.app", "Contents", "MacOS", "GrandView")
file.path(
tools::R_user_dir(package = "grandview"),
"app", "GrandView.app", "Contents", "MacOS", "GrandView"
)
} else if (is_linux()) {
file.path(
tools::R_user_dir(package = "grandview"),
"app", "grandview"
)
}
}
grandview_exists <- function() {
file.exists(grandview_app())
}

3
R/grandview-package.R

@ -10,4 +10,7 @@
#' @author Bob Rudis (bob@@rud.is)
#' @importFrom httpgd httpgd
#' @importFrom tools R_user_dir
#' @importFrom utils unzip
#' @importFrom httr GET write_disk progress
#' @importFrom jsonlite fromJSON
"_PACKAGE"

45
R/hgd.R

@ -26,6 +26,13 @@
#' (X-HTTPGD-TOKEN) field or as a query parameter.)
#'
#' @export
#' @examples \dontrun{
#'
#' hgd() # instead of httpgd()
#' # plot stuff
#' dev.off()
#' # close the viewer window manually for now
#' }
hgd <- function(host = "127.0.0.1",
port = 8288,
width = 720,
@ -38,6 +45,28 @@ hgd <- function(host = "127.0.0.1",
cors = FALSE,
token = "") {
if (is_windows()) {
message("Windows not supported yet.")
return(invisible(NULL))
}
if (!grandview_exists()) {
message(
paste0(strwrap(paste0(c(
"{grandview} requires a binary application that you ",
"must manually install because of some made up CRAN ",
"rules that other, more user-friendly (but user-insecure) ",
"environments like Python do not have to abide by. ",
"Please run `grandview::install_viewer()` to use this ",
"package."
), collaspe = "")), collapse = "\n")
)
return(invisible(NULL))
}
capture.output(
httpgd(
host = host[1],
@ -72,16 +101,10 @@ hgd <- function(host = "127.0.0.1",
}
message("{httpgd} running at ", gd_url)
message(
"{httpgd} running at ", gd_url, "\n\n",
"NOTE: for the time being, you'll have to close the viewer window ",
"manually when you close the graphics device in R."
)
}
# dir.create(
# file.path(tools::R_user_dir(package = "grandview"), "app"),
# recursive = TRUE
# )

48
R/install-viewer.R

@ -0,0 +1,48 @@
#' Install the binary viewer for your platform
#'
#' @export
install_viewer <- function() {
path.expand(normalizePath(
file.path(tools::R_user_dir(package = "grandview"), "app")
)) -> place
dir.create(place, recursive = TRUE, showWarnings = FALSE)
if (is_macos()) {
httr::GET(
url = "https://github.com/hrbrmstr/grandview/releases/latest/download/GrandView.app.zip",
httr::write_disk(file.path(place, "GrandView.app.zip"), overwrite = TRUE),
httr::progress()
)
unzip(
zipfile = file.path(place, "GrandView.app.zip"),
exdir = place,
overwrite = TRUE
)
file.remove(file.path(place, "GrandView.app.zip"))
Sys.chmod(file.path(place, "GrandView.app", "Contents", "MacOS", "GrandView"), "0755")
message("You may have to right-click and 'open' the app to accept permissions.")
system2("open", shQuote(place))
} else if (is_linux()) {
httr::GET(
url = "https://github.com/hrbrmstr/grandview/releases/latest/download/grandview",
httr::write_disk(file.path(place, "grandview"), overwrite = TRUE),
httr::progress()
)
Sys.chmod(file.path(place, "grandview"), "0755")
} else {
message("Windows not supported yet.")
}
}

22
R/zzz.R

@ -0,0 +1,22 @@
.onAttach <- function(libname, pkgname) {
if (interactive()) {
if (!grandview_exists()) {
packageStartupMessage(
paste0(strwrap(paste0(c(
"{grandview} requires a binary application that you ",
"must manually install because of some made up CRAN ",
"rules that other, more user-friendly (but user-insecure) ",
"environments like Python do not have to abide by. ",
"Please run `grandview::install_viewer()` to use this ",
"package."
), collaspe = "")), collapse = "\n")
)
}
}
}

26
README.Rmd

@ -15,6 +15,22 @@ hrbrpkghelpr::stinking_badges()
hrbrpkghelpr::yank_title_and_description()
```
This is an EXPERIMENTAL standalone viewer, written in Go, for the super-cool
{httpgd} package `remotes::install_github("nx10/httpgd")`.
The Windows viewer is not built yet because I haven't got round to it because
I detest Windows.
The goal is to have a "Quartz"-like window (for folks familiar with that on macOS) with full functionality. Right now, it's just a basic viewer (and 'save' doesn't work for some reason that I'm trying to figure out.)
If I were you, I wouldn't waste time on this package as it'll likely just get Sherlocked w/o notice by RStudio at some point and baked into their ecosystem. I made it mainly for myself as I also detest using the "browser for research" as an application runner.
I'm also just as likely to add an {httpgd} viewer functionality into RSwitch since it already functions as an RStudio Server client and it won't take much to have it work with {httpgd} directly (or via this package).
If you don't trust the pre-built viewers, `tools-raw` has what you need to make your own. They go into `tools::R_user_dir(package = "grandview"), "app")` and for the macOS one you'll need to use your own signing cert (you may need to right-click open my built one once due to faux security theatre by Apple).
Because I rely on `tools::R_user_dir()` this package requires R 4.0.0+. That was a deliberate choice since the adoption rate for R 4.0.0+ is likely low (so I have time to refine this package) and I'd rather rely on it than {rappdirs}.
## What's Inside The Tin
The following functions are implemented:
@ -39,6 +55,16 @@ packageVersion("grandview")
```
```{r eval=FALSE}
install_viewer() # you'll get prompts to do this
hgd() # it accepts params which will get passed to the viewer
# plot stuff
dev.off()
```
## grandview Metrics
```{r cloc, echo=FALSE}

116
README.md

@ -0,0 +1,116 @@
[![Project Status: Active – The project has reached a stable, usable
state and is being actively
developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active)
[![Signed
by](https://img.shields.io/badge/Keybase-Verified-brightgreen.svg)](https://keybase.io/hrbrmstr)
![Signed commit
%](https://img.shields.io/badge/Signed_Commits-100%25-lightgrey.svg)
[![Linux build
Status](https://travis-ci.org/hrbrmstr/grandview.svg?branch=master)](https://travis-ci.org/hrbrmstr/grandview)
![Minimal R
Version](https://img.shields.io/badge/R%3E%3D-4.0.0-blue.svg)
![License](https://img.shields.io/badge/License-MIT-blue.svg)
# grandview
Provides Dedicated, Platform-Specific Viewers for ‘httpgd’ Graphics
Devices
## Description
The ‘httpgd’ packages provides a super-fast, asynchronous graphics
device for R graphics via ‘svglite’ and ‘later’ packages. Tools are
provided to use dedicated, platform-specific graphics “browsers” for
‘httpgd’ graphics devices.
This is an EXPERIMENTAL standalone viewer, written in Go, for the
super-cool {httpgd} package `remotes::install_github("nx10/httpgd")`.
The Windows viewer is not built yet because I haven’t got round to it
because I detest Windows.
The goal is to have a “Quartz”-like window (for folks familiar with that
on macOS) with full functionality. Right now, it’s just a basic viewer
(and ‘save’ doesn’t work for some reason that I’m trying to figure out.)
If I were you, I wouldn’t waste time on this package as it’ll likely
just get Sherlocked w/o notice by RStudio at some point and baked into
their ecosystem. I made it mainly for myself as I also detest using the
“browser for research” as an application runner.
I’m also just as likely to add an {httpgd} viewer functionality into
RSwitch since it already functions as an RStudio Server client and it
won’t take much to have it work with {httpgd} directly (or via this
package).
If you don’t trust the pre-built viewers, `tools-raw` has what you need
to make your own. They go into `tools::R_user_dir(package =
"grandview"), "app")` and for the macOS one you’ll need to use your own
signing cert (you may need to right-click open my built one once due to
faux security theatre by Apple).
Because I rely on `tools::R_user_dir()` this package requires R 4.0.0+.
That was a deliberate choice since the adoption rate for R 4.0.0+ is
likely low (so I have time to refine this package) and I’d rather rely
on it than {rappdirs}.
## What’s Inside The Tin
The following functions are implemented:
- `hgd`: Initialize httpgd graphics device, start server, and launch
viewer.
- `install_viewer`: Install the binary viewer for your platform
## Installation
``` r
remotes::install_git("https://git.rud.is/hrbrmstr/grandview.git")
# or
remotes::install_git("https://git.sr.ht/~hrbrmstr/grandview")
# or
remotes::install_gitlab("hrbrmstr/grandview")
# or
remotes::install_bitbucket("hrbrmstr/grandview")
# or
remotes::install_github("hrbrmstr/grandview")
```
NOTE: To use the ‘remotes’ install options you will need to have the
[{remotes} package](https://github.com/r-lib/remotes) installed.
## Usage
``` r
library(grandview)
# current version
packageVersion("grandview")
## [1] '0.1.0'
```
``` r
install_viewer() # you'll get prompts to do this
hgd() # it accepts params which will get passed to the viewer
# plot stuff
dev.off()
```
## grandview Metrics
| Lang | \# Files | (%) | LoC | (%) | Blank lines | (%) | \# Lines | (%) |
| :--- | -------: | ---: | --: | ---: | ----------: | ---: | -------: | ---: |
| R | 6 | 0.67 | 134 | 0.73 | 40 | 0.48 | 53 | 0.54 |
| Go | 1 | 0.11 | 23 | 0.13 | 15 | 0.18 | 5 | 0.05 |
| make | 1 | 0.11 | 15 | 0.08 | 3 | 0.04 | 1 | 0.01 |
| Rmd | 1 | 0.11 | 11 | 0.06 | 26 | 0.31 | 40 | 0.40 |
## Code of Conduct
Please note that this project is released with a Contributor Code of
Conduct. By participating in this project you agree to abide by its
terms.

9
man/hgd.Rd

@ -57,3 +57,12 @@ need to include this token to be allowed. (Either in a request header
\description{
Initialize httpgd graphics device, start server, and launch viewer.
}
\examples{
\dontrun{
hgd() # instead of httpgd()
# plot stuff
dev.off()
# close the viewer window manually for now
}
}

11
man/install_viewer.Rd

@ -0,0 +1,11 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/install-viewer.R
\name{install_viewer}
\alias{install_viewer}
\title{Install the binary viewer for your platform}
\usage{
install_viewer()
}
\description{
Install the binary viewer for your platform
}

8
tools-raw/gdview.go

@ -22,12 +22,14 @@ func main() {
width, _ := strconv.Atoi(args[1])
height, _ := strconv.Atoi(args[2])
debug := true
w := webview.New(debug)
w := webview.New(true)
defer w.Destroy()
w.Bind("quit", funct() {
w.Terminate()
}
w.SetTitle("httpgd : " + httpgdURL)
w.SetSize(width, height, webview.HintNone)

Loading…
Cancel
Save