Hi!
This is my first post here, so sorry if something is wrong.
I am creating a gadget with shiny and miniUI and I have put a button that when pressing it launches another shiny app to the browser. To achieve this, I have used the rstudioapi :: jobRunScript function that launches a script that runs the app.
The problem is that the script depends on a variable called 'df' that is on the server and therefore it needs to be loaded with the importEnv parameter of the jobRunScript function. Here I have 2 cases:
- I assign the variable to the globalEnv with: assign('df', value = '.x', envir=globalenv()) and import the environment with: rstudioapi::jobRunScript('script.R', importEnv = environmentName(globalenv())).
In this case, everything runs correctly.
- I do exactly the same but with the current environment of the server:
assign('df', value='.x', envir=environment())
rstudioapi::jobRunScript('script.R', importEnv = environmentName(environment()))
This solution fails because can't find the 'df' value.
What is the difference?
Here is the code that doesn't run:
Gadget<-function(.df){
ui<-miniPage(
gadgetTitleBar(title = 'Gadget',
right = miniTitleBarButton("done", "Accept", primary = TRUE),
left = miniTitleBarButton("cancel", 'Cancel', primary = TRUE)),
miniTabstripPanel(
miniTabPanel('Example', icon = icon('table'),
miniContentPanel(
switchInput(inputId = 'run',
label = tags$b('example'),
offStatus = 'danger',
value = FALSE)
))))
server<-function(input, output, session, .x = .df){
assign('df', value = .x, envir = environment())
observeEvent(input$run,{
if(isTRUE(input$run)){
rstudioapi::jobRunScript('script.R',
importEnv = environmentName(environment()))
}
}}
runGadget(ui, server, viewer = dialogViewer("recipesGadget", width = 750, height = 750))
}