I have a customized function will create html using fluidrow() with different arguments. I have created a list that I want to pass to this customized function.
Here is the function
rawname = function(name){
x = paste0(name, "_raw_ww_plot")
return(x)
}
w10 = function(name){
x = paste0(name, "_10ws_plot")
return(x)
}
w20 = function(name){
x = paste0(name, "_20ws_plot")
return(x)
}
listname = function(name){
x = list(c(map_chr(name, w10), "Previous 10 Weeks"),
c(map_chr(name, w20), "Previous 20 Weeks"),
c(map_chr(name, rawname), "All Time"))
return(x)
}
make.fluidrow = function(html, list, bar = hr(), col = 12,
box.num = 2){
htmlvar = sapply(html, function(x) {
paste0("<div style='text-align:center'><h3>",
x,
"</h3></div><br>")})
if (box.num == 1){
row = fluidRow(
column(col,
box(HTML(htmlvar[1]),
do.call(tabsetPanel,
lapply(list, function(y){tabPanel(y[2],
plotlyOutput(y[1],
height = "100%"), width = 6)}))),
bar))
} else if (box.num == 2)
row = fluidRow(
column(col,
box(HTML(htmlvar[1]),
do.call(tabsetPanel,
lapply(list, function(y){tabPanel(y[3],
plotlyOutput(y[1],
height = "100%"),
width = 6)}))),
box(HTML(htmlvar[2]),
do.call(tabsetPanel,
lapply(list, function(y){tabPanel(y[3],
plotlyOutput(y[2],
height = "100%"),
width = 6)}))),
bar))
return(row)
}
here is the list
a1 = list(c("San Francisco Public Utilities Commission (SFPUC) Oceanside",
"San Francisco Public Utilities Commission (SFPUC) Southeast"),
listname(c("SFOcean", "SFPUC_SE")))
a2 = list(c("East Bay Municpal Utility District (EBMUD)",
"Central Contra Costa Sanitation District (CCCSD)"),
listname(c("EBMUD", "CCCSD")))
a3 = list(c("Silicon Valley Clean Water",
"Palo Alto Regional Water Quality Control Plant"),
listname(c("SVCW", "PA")))
alist = list(a1, a2, a3)
Inside the tabPanel(), I am trying to loop through the alist and create an output that is equal to the output from the follow codes
make.fluidrow(html = a1[[1]], list = a1[[2]][3], bar = br()),
make.fluidrow(html = a2[[1]], list = a2[[2]][3], bar = br()),
make.fluidrow(html = a3[[1]], list = a3[[2]][3], bar = br()))
I have tried this following code but it creates a list of html code instead of the continuous html code that will be created by the code just about this one
map(alist, ~make.fluidrow(html = .[[1]], list = .[[2]][3], bar = br()))
And I have read online and saying do.call can make the continuous html code. I have tried the following code but it gave an errors saying "Error in do.call(make.fluidrow, c(alist, list(html = .[[1]], list = .[[2]][3], : object '.' not found". I just don't know how to pass the arguments refer to the alist like code that I used map function
do.call(make.fluidrow, c(alist, list(html = .[[1]], list = .[[2]][3], bar = br())))
how can I write a code that will loop through the each item in alist and create a continuous html codes. Also, would like to know if the arguments can refer to the list in the do.call function and if so, how to do it.