2

I used this example 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. enter image description here Anyone knows how to get rid of the TRUE without getting the sourceme.r text into the app. Maybe source is not the function is should use?

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"))
)
Community
  • 1
  • 1
Tim_Utrecht
  • 1,459
  • 6
  • 24
  • 44

1 Answers1

3

Make the contents of sourceme.r a function that returns sidebarMenu. Then place the source call outside of the server function, and call the new function inside the server function to return the sidebarMenu.

dommer
  • 19,610
  • 14
  • 75
  • 137
  • Thanks, already figured it out myself but will obviously accept it. – Tim_Utrecht Nov 18 '16 at 13:51
  • Dear @dommer, could you help with this https://stackoverflow.com/questions/59129562/in-r-shiny-how-to-fix-error-in-sourcing-app-as-nothing-changes-when-clicking-on?fbclid=IwAR2XoSXF7weHkpZ2a9rOXa69KgKcgeMGO6xdQ2Xv1ZRUKWmAa7bVeZlktMo – John Smith Dec 02 '19 at 06:34