dgkf / dgkf/scriptgloss

Further considerations for callModule processing

Open
#17 0 comments 0 reactions 0 assignees View on GitHub
enhancement help wanted
Dominant language
R
Stars
10
Forks
2
PR merge metrics
No merged PRs in 30d

Description

A long follow-up to #1 and #2 to discuss handling of `callModule` calls.

Using the [nested shiny modules example app](https://github.com/dgkf/scriptgloss/blob/master/app-examples/nested-modules-static-code-generation/app.R), the code it generates looks like this at the moment (below).

It's not particularly pretty, even by automatically generated code standards. It requires wrapping the output list and return result of the callModule call in an additional class structure and then using special accessor functions to extract the various components.

```r
library(scriptgloss)
library(shiny)
library(dplyr)
library(ggplot2)
my_data <- ggplot2::mpg
scatterPlot <- function(data, cols) ggplot(data, aes_string(x = cols[1], y = cols[2])) + geom_point(aes(color = selected_)) + scale_color_manual(values = c("black", "#66D65C"), guide = FALSE)
linkedScatter <- function(input, output, session, data, left, right) {
uniquesTable <- function(input, output, session, data, col) {
filteredData <- function() {
data() %>% dplyr::filter(selected_) %>% .[[col()]]
}
output$table <- function() {
table(filteredData())
}
uniques <- function() {
unique(filteredData())
}
.return <- uniques
return(structure(output, return = .return, submodules = structure(list(), .Names = character(0)), class = c("scriptgloss_module", "list")))
}
uniques_table <- uniquesTable(input = structure(list(), .Names = character(0)), output = list(), session = NULL, data = dataWithSelection, col = function() right()[[1]])
u <- callStaticModule(uniques_table)
dataWithSelection <- function() {
brushedPoints(data(), input$brush, allRows = TRUE)
}
output$plot1 <- function() {
scatterPlot(dataWithSelection(), left())
}
output$plot2 <- function() {
scatterPlot(dataWithSelection(), right())
}
output$uniques <- function() {
paste("Unique Values:", paste(as.character(u()), collapse = ", "))
}
.return <- dataWithSelection
return(structure(output, return = .return, submodules = list(uniques_table = uniques_table), class = c("scriptgloss_module", "list")))
}
scatters <- linkedScatter(input = structure(list(), .Names = character(0)), output = list(), session = NULL, data = function() my_data, left = function() c("cty", "hwy"), right = function() c("drv", "hwy"))
df <- callStaticModule(scatters)
sprintf("%d observation(s) selected", nrow(dplyr::filter(df(), selected_)))
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.