tomsu
tomsu

Reputation: 375

Multifile shiny dashboard

I try to rebuild my application as in the link. I have a multitematic dashboard and I would like to have each topic in separate ui and server files to have better control of the code.

The main file (app.R) is contacting with other files eg UI using source(file.path("ui", "tab1.R"), local = TRUE)$value tab1.R looks like:

tabPanel("Tab 1", uiOutput("content1")) (content1 is in server file).

I would like to have possibility to put more then on tabPanel in one file. I thought that i can do something like that: tab1.R looks like:

aaa <- tabPanel("Tab 2", uiOutput("content2")) 
bbb <- tabPanel("Tab 1", uiOutput("content1"))

And then contact with them using:

source(file.path("ui", "tab1.R"),  local = TRUE)$aaa
source(file.path("ui", "tab1.R"),  local = TRUE)$bbb

But i get ERROR:

Error in attr(x, "selected") <- TRUE : 
  attempt to set an attribute on NULL

I could not find answer for that anywhere so I disated to write here for help

Upvotes: 0

Views: 242

Answers (1)

tomsu
tomsu

Reputation: 375

I found imo the best way, I just used the functions:

aaa <- function(){tabPanel("Tab 2", uiOutput("content2"))}
bbb <- function(){tabPanel("Tab 1", uiOutput("content1"))}

And then on the top on file I upload source:

source(file.path("ui", "tab1.R"),  local = TRUE)

Now I can normally use functions in code:

aaa()
bbb()

Upvotes: 1

Related Questions