Reputation: 555
I know that this question has been asked repeatedly, but the usual solutions using eval(parse(text = x))
and get(x)
have not been working for me.
I would like to store function arguments as either a string or in a list and pass them into a function:
library(shiny)
library(shinymanager)
library(shinythemes)
## this works but is not what i want
ui <- secure_app(
theme = shinytheme("flatly"),
tags_bottom = tags$h5("If you are having issues logging in - chill and order a pizza."),
fluidPage()
)
server <- function(input, output, session) {
}
shinyApp(ui = ui, server = server)
Something like this is what I want, which current does not work:
arguments <- "theme = shinytheme('flatly'),
tags_bottom = tags$h5('If you are having issues logging in - chill and order a pizza.')"
ui <- secure_app(
arguments,
fluidPage()
)
server <- function(input, output, session) {
}
shinyApp(ui = ui, server = server)
Upvotes: 2
Views: 52
Reputation: 7106
Maybe this is helpful:
library(shiny)
library(tidyverse)
library(rlang)
library(shinymanager)
library(shinythemes)
#start a new line between arguments
arguments <- "theme = shinytheme('flatly'),
tags_bottom = tags$h5('If you are having issues logging in - chill and order a pizza.'),
ui = fluidPage()"
cleaning <- str_split(arguments, ',\n') %>%
transpose() %>%
flatten() %>%
map(~ str_split(.x, ' = ')) %>% #separate the argument name from the code to evaluate
set_names(map(., ~.x[[1]][[1]]))
listing <- cleaning %>%
map_df(~ .x[[1]][[2]]) %>% # a dataframe where each cell is an expression
map(~eval(parse(text = .x[[1]])))
ui <- exec(secure_app, !!!listing) #pass the arguments as a list
server <- function(input, output, session) {
}
shinyApp(ui = ui, server = server)
Upvotes: 1