Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to open files using navigateToFile on startup #269

Open
shahronak47 opened this issue Nov 29, 2022 · 2 comments
Open

Unable to open files using navigateToFile on startup #269

shahronak47 opened this issue Nov 29, 2022 · 2 comments

Comments

@shahronak47
Copy link

On startup of a project I want to open two files. I have created .Rprofile file for the project which has the following content -

if(rstudioapi::isAvailable()) {
  rstudioapi::navigateToFile('R/ui.R')
  rstudioapi::navigateToFile('R/server.R')
}

but whenever I open this project those two files (ui.R and server.R) don't open, nor is there any error message regarding it. I think that is because rstudioapi::isAvailable() returns FALSE.

To confirm, I removed the if condition from .Rprofile and I get Error: RStudio not running.

How do I fix this? I think this issue #100 is similar to mine but it is not yet resolved and I was unable to use the hook suggestion.

Any ideas?

@gadenbuie
Copy link
Member

I think this will work if you add it to the .Rprofile in your project.

setHook("rstudio.sessionInit", action = "append", function(newSession) {
  rstudioapi::navigateToFile('R/ui.R')
  rstudioapi::navigateToFile('R/server.R')
})

@shahronak47
Copy link
Author

Thanks @gadenbuie , that worked. But I don't know this somehow blocks using the Run App button for shiny. As you mentioned I added this in my .Rprofile file and it opens these two ui and server files upon launch but when I click on Run App button it print runapp('R/') in the console and waits. Nothing happens after that.

Do you have any idea what might be causing that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants