Inserting R code in Shiny application GUI

I would like to insert this code in my shiny application o that the browsing window appears in the GUI.

How could I do this?

It looks to me like you want to

  • select a file
  • change parameters
  • do something with the file

Obviously, there is flexibility on the types of parameters you want to edit, the way in which you edit them, and what you do with the file once the parameters are set. For the general approach, though, you might have a look at the Shiny gallery, and specifically this upload example. It is weird to think about uploading when you are running locally, but the Shiny service is in one sense independent from your Operating System, so an upload is the right way to go.

If you want to set defaults in a file, then you might look at the config package, although this will have limitations if you edit the file in your process.

Thanks! How about using rhandsometable? What would be approach in order to upload edit and save the file? An will the file be saved in the local directory or in the RStudio server?

I'm not familiar with rhandsometable. Do you mean rhandsontable? That would be for editing the data in the UI, which is more the 2nd / 3rd bullet. To get data into the UI, you will either be pulling it from a source other than the UI (database, file on the operating system running the R process, or user-provided file through an "Upload). Then to get data out of the UI, you will be pushing it to a source other than the UI (database, file on the operating system that is running the R process via one of the save or write methods, or user-provided file through a "Download"). You do have to think a bit differently than just your "normal" R session, though, because the interface is a web browser instead of an R console.

It sounds like you need to do a bit more thinking about what exactly you are trying to set up, but it sounds like you definitely have the tools to do so. Note that there are security implications of all of these processes if you expose the app to users, so it is good to keep that in mind.

Thank you! What I am trying to do is for the user of the application to be able to find a file (browse) in the local directory (PC), open the file, make changes and save it again. It probably be helpful if the file can be saved to the local PC and to the RStudio server for processing by the program. I am not sure yet, but what I would like to learn is how to integrate the ability to browse with the ability to open the file. make modifications and change it. I know how to browse and upload a the file, but I do not know how to open the file to make changes, save it and where to save it (local or server?). Do I have to save it to the RStudio server for further processing or do I need to download it first and then save it, and uploaded again for processing?. Also, Where can I find the functionality. Is this something I can do with fileInput, tableOutput and rhandsontable functions?

You definitely can upload / edit / save using fileInput, rhandsontable and download (i.e. the examples above). You can either save the file to the server or have the user download it - how you negotiate that will depend on your desires. Usually, if you want the user to interact with / interactively browse the file you would have them save it somewhere. Usually, the client is not allowed to browse on the server for security reasons - it sounds like you may need to read up on the client-server model. You definitely have the tools that you need, though! You should probably narrow your focus on the types of files that you want to open/edit, as being able to open / edit any generic file-type would be a lot of work.

Thanks! I have one more question: I know that in order to integrate an R script into my app I have to use source(script.R). The problem is that some times there is not output to display (renderplot), and the object to display does not run inside a reactive context. If I need to know if the R script statements are executing, how can I capture the value of the variables in the script? In other words, there are not inputs being entered through the UI.

It sounds like you may want to read up on Shiny modules for splitting up app code. You also may be suffering from a lack of functional programming. If your "script" is changed to Rmarkdown, you might look at parameterized reports as well, which can behave like a function call through rmarkdown::render. Finally, if you're really going for IDE-like behavior, you might explore RStudio Cloud and learnr tutorials. Specifically, these primers are a good illustration of the functionality available in the learnr package.

Thanks very much for your help!