Adds a user-defined function to the av Shiny app
Usage
av_add_analytic(
runcode,
func_name,
helpstr = "user function",
focus = "MAIN",
data_req = "pxd;earn;earnest",
message_str = "",
delay_save_state = FALSE
)Arguments
- runcode
Code string user must run to call the function.
- func_name
Name of function run when analytic is called. If an empty string is supplied, the runcode will be de-registered.
- helpstr
(default: "user function"): A string comment to ad to the av.h (help) command
- focus
(default: "MAIN") String with tab name to set focus to when command is run
- data_req
(default: "pxd;earn;earnest") A semicolon list of required data tables. Used for Lazy data loading.
- message_str
(default "") Additional string to add to output messages
- delay_save_state
(default: FALSE) Do not save state to cache files. Used for speed optimization
Details
Adds or removes a new command to the av_runShiny app
When the av_runShiny() app is run, users can call functions to provide analytics based on asset strings in the command line.
This function allows users to add their own analytics by registering a function which takes, as inputs
todo: The command line and any subsequent parameters as a space delimited stringrv: Reactive values supplied by the Shiny app. In particular the parameterrv$istr1contains the semicolon delimited set of assets prior to the command invocation. The registered function should return a (possibly named, see vignette) list containing one or moregt()tables,dygraphs(), orggplots()to be displayed when the command is run. See vignette for specfic details
The function specified must be available (i.e in
.GlobalENv()) to the Shiny app when the command is run. Otherwise an error message will be displayed.If the specified command has already been registered, a message will be given and the internal data will be overridden.
Examples
if (FALSE) { # \dontrun{
my_testfunc <- function(todo,rv) {
message("todO: ",todo," with asset string ",rv$istr1)
n_to_return <- c(strsplit(todo," "),"3")[[2]] |> as.numeric()
table1 <- head(mtcars,n_to_return) |> gt()
table2 <- data.table(asset=strsplit(rv$istr1,";")) |> gt()
plot1 <- ggplot(mtcars,aes(mpg,disp)) + geom_point()
return(list(table1, table2, plot1))
}
av_add_analytic("TEST","my_testfunc",helpstr="a test func")
# From the app; run "QQQ;SPY test 5"
# From the app: run "av.h"
} # }