I am successful in using global.R to pass data to ui.r and server.R while developing in RStudio. However when I migrate my code to server neither ui.R nor server.R are able to read global.R. I am using Shiny Server (not pro). What could be causing this?
My code looks like this (it is not reactive)
#global.R
x = 10
#ui.R
print(x)
> 10 #in RStudio viewer
> Error: object 'x' not found #on Shiny Server
Following sigmabeta's answer below I made changes to server.R
and global.R
however I am looking for the server to reset x to another value so that it can be read by ui.R
. This is what my code is now
#global.R
x = 10
get_x_value <- function (n) {
x = n+1
return x
}
#server.R
source("./global.R")
shinyServer(function(input, output) {
values <- reactiveValues()
observe ({
values$x <- get_x_value(5)
})
})
#ui.R
print(x)
> 6 #in RStudio viewer
> 10 #on Shiny Server
This is the actual code in ui.R
where I am trying to set the status of the box based on the values already computed in server.R
library(shinydashboard)
dashboardPage(
Header = dashboardHeader(title = 'Test'),
Sidebar = dashboardSidebar
(
sidebarMenu
(
menuItem("ABC", tabName = "ABC")
)
),
Body = dashboardBody
(tabItems
(
tabItem(
tabName = "ABC",
fluidRow
(
box
(
status = if (x==6) "info" else "danger" ,
solidHeader = TRUE
)
)
)
)
)
)