How and where to create config.yml file to get the connection details

I am trying deploy a flexdashboard where I am extracting the data from database and then publishing my results. But since the database is not one of the professional drivers I need to config.yml file to define my connection details. Can you help me to understand how should I create this config.yml file? Is it using Rmarkdown.I have installed packages 'config' and 'configr' and also referred to this article . I am stuck in this first step of creating the configuration file.

What did you try for now from the website you found ?

You can follow the advice here :

A yaml file is just a text file with extension yml. So you can create a config.yml file as any other text file. (with an editor or with R using file.create("config.yml") to get an empty file to complete).
Then you write in the file with yaml syntax, following the example in the db website, and also from the config :package: doc:

For database, I would avdvice to follow the recommandion in db website and use environment variable to store credential outside of the config.yml file.

Hope it helps

You need to use : everywhere not =

Take care at the indentation in the yaml syntax also. The examples should help you.

In your screenprint the editor indicates that there is something wrong in line6:
line2-line5 are rendered in blue but line6 is not recognized as correct yaml.
When I inserted a blank after the : in all lines everything was read correctly.

If you read the configuration parameters in variable config you should also use
Driver=config$driver etc. Therefore it less typing to read the configuration parameter in dw :
dw <- config::get(file="config.yml")

1 Like

Thanks a lot for the help. It worked

Thanks you

Glad it finally works ! :+1:

You are also missing a level of indentation for all field after datawarehouse:

If would then be Driver=config$datawarehouse$driver

Or you don’t need this line 3 at all maybe.

Thanks a lot for all the help. Now I am able to publish the flexdashboard by extracting the data from datawarehouse.

1 Like

Awesome !

If your question's been answered (even by you!), would you mind choosing a solution? It helps other people see which questions still need help, or find solutions if they have similar problems. Here’s how to do it:

Ya sure...

Done :+1:

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

Thanks for the reply.
I could create the config.yml file using file.create and in the config.yml store all the connection details as below

driver: '/usr/lib/snowflake/odbc/lib/'
server: ''

Now I am creating another .Rmd file to load this file which shows error. Attaching the snapshot. Can you please suggest what should be done

Ya changed that.

driver: '/usr/lib/snowflake/odbc/lib/'
server: ''

Still the error is same. How can I call my connection parameters?

My R version is the latest R 4.0

Are you indenting correctly this ? Can you share the file content with proper code formatting ?

Also please read the documentation from the links above. You should use the get() function from the config package. See the doc.

Attaching the config.yml file. Please let me know if it is correct
Masked few details!!
I tried with get() also in R script with
but getting the same error:
Error in yaml.load(readLines(con), error.label = error.label, ...) :
(/home/rstudio-user/config.yml) Scanner error: while scanning a simple key at line 6, column 3 could not find expected ':' at line 7, column 3