组织更大的应用程序的最佳实践是什么
但是,在shiny 的环境中,我可以采用哪些独特的技巧和技巧来让shiny 的代码看起来更好(更可读)?
- 利用面向对象编程技术
- 在
server.R
中,哪些零件应该采购? - 包含markdown 文档、图片、,
例如,如果我在每tabPanel
个元素中使用navbarPage
和tabsetPanel
,那么在添加了几个UI元素之后,我的代码开始看起来非常混乱.
示例代码:
server <- function(input, output) {
#Here functions and outputs..
}
ui <- shinyUI(navbarPage("My Application",
tabPanel("Component 1",
sidebarLayout(
sidebarPanel(
# UI elements..
),
mainPanel(
tabsetPanel(
tabPanel("Plot", plotOutput("plot")
# More UI elements..
),
tabPanel("Summary", verbatimTextOutput("summary")
# And some more...
),
tabPanel("Table", tableOutput("table")
# And...
)
)
)
)
),
tabPanel("Component 2"),
tabPanel("Component 3")
))
shinyApp(ui = ui, server = server)
对于组织ui.R
个代码,我从GitHub找到了非常好的解决方案:radiant code
server <- function(input, output) {
# This part can be in different source file for example component1.R
###################################
output$component1 <- renderUI({
sidebarLayout(
sidebarPanel(
),
mainPanel(
tabsetPanel(
tabPanel("Plot", plotOutput("plot")),
tabPanel("Summary", verbatimTextOutput("summary")),
tabPanel("Table", tableOutput("table"))
)
)
)
})
#####################################
}
ui <- shinyUI(navbarPage("My Application",
tabPanel("Component 1", uiOutput("component1")),
tabPanel("Component 2"),
tabPanel("Component 3")
))
shinyApp(ui = ui, server = server)