采购动态 UI 使 'TRUE' 闪亮
Sourcing dynamic UI gives 'TRUE' in shiny
我使用了 to get a dynamic UI for a shiny app. I'm now trying to source the sidebar panel. But when I do this, I get an ugly 'TRUE' in the sidebar. 任何人都知道如何在不将 sourceme.r 文本放入应用程序的情况下摆脱 TRUE。也许 source
不是应该使用的功能?
require(shiny)
require(shinydashboard)
mainbody <- div(tabItems(
tabItem(tabName = "t_item1", class = "active", box(title = "Item 1 information")),
tabItem(tabName = "t_item2", box(title = "Item 2 information")),
tabItem(tabName = "t_item3", box(title = "Item 3 information"))
)
)
header <- dashboardHeader(title = "dashboard header")
sidebar <- dashboardSidebar(uiOutput("sidebarpanel"))
body <- dashboardBody(uiOutput("body"))
ui <- dashboardPage(header, sidebar, body)
server <- function(input, output, session) {
output$sidebarpanel <- renderUI({
# if (USER$Logged == TRUE) {
# div(
source('~/sourceme.r')
# sidebarMenu(
# menuItem("Item 1", tabName = "t_item1", icon = icon("line-chart")),
# menuItem("Item 2", tabName = "t_item2", icon = icon("users")),
# menuItem("item 3", tabName = "t_item3", icon = icon("dollar"))
# )
# )
})
output$body <- renderUI({
mainbody
})
}
shinyApp(ui, server)
sourceme.r:
sidebarMenu(
menuItem("Item 1", tabName = "t_item1", icon = icon("line-chart"), selected = TRUE),
menuItem("Item 2", tabName = "t_item2", icon = icon("users")),
menuItem("item 3", tabName = "t_item3", icon = icon("dollar"))
)
使 sourceme.r
的内容成为 函数 ,即 return 的 sidebarMenu
。然后把source
调用放在server
函数外面,在server
函数里面调用新函数到return sidebarMenu
.
我使用了 source
不是应该使用的功能?
require(shiny)
require(shinydashboard)
mainbody <- div(tabItems(
tabItem(tabName = "t_item1", class = "active", box(title = "Item 1 information")),
tabItem(tabName = "t_item2", box(title = "Item 2 information")),
tabItem(tabName = "t_item3", box(title = "Item 3 information"))
)
)
header <- dashboardHeader(title = "dashboard header")
sidebar <- dashboardSidebar(uiOutput("sidebarpanel"))
body <- dashboardBody(uiOutput("body"))
ui <- dashboardPage(header, sidebar, body)
server <- function(input, output, session) {
output$sidebarpanel <- renderUI({
# if (USER$Logged == TRUE) {
# div(
source('~/sourceme.r')
# sidebarMenu(
# menuItem("Item 1", tabName = "t_item1", icon = icon("line-chart")),
# menuItem("Item 2", tabName = "t_item2", icon = icon("users")),
# menuItem("item 3", tabName = "t_item3", icon = icon("dollar"))
# )
# )
})
output$body <- renderUI({
mainbody
})
}
shinyApp(ui, server)
sourceme.r:
sidebarMenu(
menuItem("Item 1", tabName = "t_item1", icon = icon("line-chart"), selected = TRUE),
menuItem("Item 2", tabName = "t_item2", icon = icon("users")),
menuItem("item 3", tabName = "t_item3", icon = icon("dollar"))
)
使 sourceme.r
的内容成为 函数 ,即 return 的 sidebarMenu
。然后把source
调用放在server
函数外面,在server
函数里面调用新函数到return sidebarMenu
.