-
Notifications
You must be signed in to change notification settings - Fork 655
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Functions to Refactor #163
Comments
I should enhance this method, so that all library related settings that were initialized get re-initialized. Here is how the new setLib = function(lib, ...){
lib <<- lib; LIB <<- get_lib(lib)
templates <<- modifyList(list(
page = 'rChart.html',
chartDiv = NULL,
script = file.path(LIB$url, 'layouts', 'chart.html')
), list(...))
} |
The print method includes if (is.null(templates$chartDiv)){
chartDiv = sprintf("<%s id='%s' class='rChart %s'></%s>",
container, params$dom, LIB$name, container)
} else {
chartDiv = render_template(templates$chartDiv, list(chartId = params$dom))
} I can rewrite it so that in templates$chartDiv <<- "
<{{container}} id = '{{ chartId }}' class = 'rChart {{ lib }}'>
</{{ container}}>
" Once chartDiv = render_template(templates$chartDiv, list(
chartId = params$dom,
lib = LIB$name,
container = container
)) |
Currently, renderChart2 <- function(expr, env = parent.frame(), quoted = FALSE) {
func <- shiny::exprToFunction(expr, env, quoted)
function() {
rChart_ <- func()
cht_style <- sprintf("<style>.rChart {width: %spx; height: %spx} </style>",
rChart_$params$width, rChart_$params$height)
cht <- paste(capture.output(rChart_$print()), collapse = '\n')
HTML(paste(c(cht_style, cht), collapse = '\n'))
}
} |
show I can overload the show method so that charts can be saved as html files and embedded as iframe. This would solve a lot of issues related to interference between js files. Here is a simple implementation using options. I tested it and it works. I need to refactor the show method so that all the overloaded functions are consistent and are controlled in more or less the same manner. if (!is.null(getOption('rcharts.vis.tag')) &&
getOption("rcharts.vis.tag") == 'iframe'){
file_ = sprintf("assets/img/%s.html", params$dom)
.self$save(file_)
cat(sprintf("<iframe src=%s></iframe>", file_))
return(invisible())
} Here is a list of ways in which the show method can work currently.
@reinholdsson, @timelyportfolio, if you have any thoughts on how to make these consistent and easy to use, post your ideas here. This would be an important refactoring, and I want to get it right. |
thorei is someone different - please address the right person. |
@thorei My apologies. I confused his twitter handle with his github handle. |
getMode This function chooses the best NOTES:
`%?=%` <- function(a, b){
ifelse(!is.null(a), a == b, FALSE)
} getMode = function(mode_){
# if mode_ is specified, just return it
if(!is.null(mode_)){
return(mode_)
}
# if rcharts.mode is specified, just return it
if(!is.null(getOption('rcharts.mode'))){
return(getOption('rcharts.mode'))
}
# if knitr is in progress, return mode = iframe, else static
if(getOption('knitr.in.progress') %?=% TRUE){
mode_ = 'iframe'
} else {
mode_ = 'static'
}
return(mode_)
} |
A more compact version of getMode = function(mode_){
default = ifelse(getOption('knitr.in.progress') %?=% TRUE, 'iframe', 'static')
mode_ = mode_ %||% getOption('rcharts.mode') %||% default
return(mode_)
} Would it be better to use I can then think of having a set of options to control
This sounds very promising. |
I want to overload this function so that it takes a string or a filename for the template
I can enhance this function by checking for the template in multiple locations. The default is the current path, and if not found it could search in the root path of the package, or
libraries/:lib
. This would allow more compact code.The text was updated successfully, but these errors were encountered: