我有以下閃亮,應用程序,組織方式如下如何編程生成模板[R代碼和目錄結構
-- base_app
|-- server.R
|-- ui.R
`-- www
例如,server.R
包含此行:
infile <- "foo.txt"
# do something with infile
我m尋找一種方式來自動生成應用程序目錄和文件內容。例如,如果我們定義兩個參數:
應用程序名稱
mycool_app
輸入文件:
bar.txt
之後,將根據在base_app
定義的模板生成此。
-- mycool_app
|-- server.R
|-- ui.R
`-- www
而且新server.R
將包含infile <- "bar.txt"
。我看着 whisker。但它不提供文件內編碼的模板,只能通過字符串。我正在考慮能力ala Python's Jinja2。
在R中做這件事的最好方法是什麼?
更新:
又如爲ui.R
:
# Example of ui.R
# Choices differs from analysis to analysis
# Hand coded
# ---------------------------
choices_list <- list(
"A. Rumef.XXX vs Salt" = "Group_A.Rumef.XXX_vs_Salt.iv",
"B. Bra.XXX vs Salt" = "Group_B.Bra.XXX_vs_Salt.iv",
"C. Salt.Rumef vs Bra" = "Group_C.Salt.Rumef_vs_Bra.iv",
"D. XXX.Rumef vs Bra" = "Group_D.XXX.Rumef_vs_Bra.iv"
)
selected_choices <- "Group_A.Rumef.XXX_vs_Salt.iv"
analysis_name <- "Cool Analysis"
fc_slider_threshold <- 0.8
# Do more things with those variables.
內容choices_list
,selected_choices
,analysis_name
,fc_slider_threshold
將被供給到被包括在新生成的mycool_app
。
我不知道我的理解。你的問題和簡單地將整個應用程序文件夾從一個位置複製到另一個位置有什麼區別? – Florian
@Florian我有很多參數集,並且我想創建多個應用程序。我想讓這個Shiny-apps一代自動化。 – pdubois
對不起,我還沒有100%清楚。我看到一個包含'infile < - 「foo.txt」'的server.R,並且該server.R文件也在另一個文件夾中創建。你有什麼樣的參數,你期望他們執行什麼樣的行爲?現在看起來像file.copy()會起作用。 – Florian