在Shiny应用程序文件中,包含依赖项的最好方法是在全局文件(如global.R)中加载这些包。这样,无论使用哪个脚本文件,依赖项都会被加载,因为全局文件会在应用程序启动时被加载。以下是一个示例:
global.R:
library(shiny)
library(ggplot2)
library(dplyr)
app.R:
shinyApp(
ui = fluidPage(
# your UI code here...
),
server = function(input, output) {
# your server code here...
}
)
这种方法还可以更好地组织代码,并使应用程序文件更易于阅读和维护。