Monday 6 January 2020

r - How to edit a .yml file in Shiny



I have a Shiny application which pulls data from various APIs and databases. All the sensitive data pertaining to credentials, usernames, passwords etc. are stored in a config.yml file. The code within the Shiny app calls variables within the config.yml file for connecting to different APIs/databases.




I have also created an administrator login for the Shiny application and want to provide access to the administrator for making changes in the config.yml file. The Shiny app has a separate tab called Admin whiich opens up when the administrator logs in. How can I open the config.yml file and allow edits by the administrator and save it?


Answer



I created a tab for the configuration file and using Shiny Ace as editor:



library(shinyAce) 

# UI

aceEditor(
outputId = "someID",

value = read.delim("config.yml"),
placeholder = "Connection configuration file"
),

actionButton("save", label = "Save Configuration")

# Sever

observeEvent(input$save, {
write(x = input$someID, file = "config.yml")

print("file saved")

})


Then you can call to the config.yml and apply the configurations.


No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...