{"id":14066962,"url":"https://github.com/nhihin/sampleDB","last_synced_at":"2025-07-30T00:31:55.200Z","repository":{"id":86696160,"uuid":"435374806","full_name":"nhihin/sampleDB","owner":"nhihin","description":"Store and manage samples in SQL database through shiny application.","archived":false,"fork":false,"pushed_at":"2021-12-06T05:47:26.000Z","size":589,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-12-04T07:36:19.038Z","etag":null,"topics":["bioinformatics","r","shiny","sql"],"latest_commit_sha":null,"homepage":"","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nhihin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-12-06T05:45:26.000Z","updated_at":"2022-01-23T22:02:10.000Z","dependencies_parsed_at":null,"dependency_job_id":"0f7468a8-ece6-4ab3-a697-b6ef486130ad","html_url":"https://github.com/nhihin/sampleDB","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/nhihin/sampleDB","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nhihin%2FsampleDB","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nhihin%2FsampleDB/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nhihin%2FsampleDB/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nhihin%2FsampleDB/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nhihin","download_url":"https://codeload.github.com/nhihin/sampleDB/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nhihin%2FsampleDB/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267785738,"owners_count":24144120,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-29T02:00:12.549Z","response_time":2574,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bioinformatics","r","shiny","sql"],"created_at":"2024-08-13T07:05:21.272Z","updated_at":"2025-07-30T00:31:54.858Z","avatar_url":"https://github.com/nhihin.png","language":"R","funding_links":[],"categories":["R"],"sub_categories":[],"readme":"# Shiny Sample Management\n\nThis is a work in progress Shiny application for managing samples. The goal is\nto store sample data in a `SQL` database that can be built, queried and added\nto with ease. A big focus of mine will be on data-consistency. What I mean by\nthis is:\n\n* Mandatory meta-data fields that must be populated\n* Meta-data entries conforming to pre-defined specifications (field specific)\n\nWhilst the main focus of this repository is the `Shiny` application,\nI have provided some scripts to help build a starting database.\n\nWhat I hope to build is a Shiny application that enables users to:\n\n* View their sample records\n* Filter samples on specific fields\n* Ingest samples into the database from the application\n* Validate incoming data to prevent contaminating the database\n* Export sample information from the database\n* Visualise sample locations on a dynamic world-map\n\n## Application preface\n\nThis project isn't going to be optimal. I've not written many Shiny applications\nand wanted to build this for my lab-group. I've also not had much experience\nwith building, interacting with or maintaining databases, so I have no expectation\nthat how I've implemented *anything* is going to be best-practices.\n\nThe code in this server has been written with best intentions. I know I\ncould make a more modular application with Shiny modules, but the truth is that\nwhilst I got many of the sidebar filters working, it was taking more time than\nI'd like to admit to get the application doing what I wanted. Consequently I\nsettled for the approach I've taken.\n\nSimilarly, the database implementation code is very simple. I've essentially\njust looked at a few examples on the net and got something working that does\nwhat I want. My code is not perfect, but it's stable enough and does what I need\nit to do. I'm sure there are edge-cases (or not so edge-cases) that would bring\neverything crashing down, but so far I've been in the clear.\n\n### Other Users Adapting This Code\n\nI have no issue with anyone taking this code and adding to it, updating it or\ntotally re-writing it. The biggest limitations to adapting this code for your\nown sample management include:\n\n- Hard-coded columns\n- Sidebar filters written specifically for the hard-coded columns\n- Non-modular design - a modular application may help with the points above\n- Database management - `dbplyr` is a package I use heavily, but it is designed\nfor database querying, not managing. As such, my code 'collects' the data from\nthe DB, appends new samples then **overwrites** the existing database with the\nnew file. Not great, but does the trick.\n\nThere are others, but these are the things that will need to be considered when\nadjusting this code. If you have experience with `R` and `Shiny` then you'll\nprobably be able to navigate these issues pretty easily, it'll just be more\ntime consuming than anything else.\n\n## Getting started\n\nWith that out of the way, I'll demonstrate below how to set up a basic database\nusing the column specifications from this repository and then start up the\napplication. The script used to build the example dataset can be found\n[here][exampleData] for reference.\n\n### Step 1: Download a template file\n\nIf you do not already have a \"database\"\" of samples (e.g. in a Excel spreadsheet\nor something...) ready to go, you can run the `exportEmptySampleSheet()` command\nto download a *CSV* template file that you can edit.\n\n```r\nexportEmptySampleSheet(\n  path = '/path/to/outdir',\n  filename = 'template-sample-sheet'       # Optional argument\n)\n```\n\nIf the `filename` argument is left as default, this will create the following\nfiles at the `path` location:\n\n- **template-sample-sheet.csv**: File to edit with your own sample information\n- **template-sample-sheet-descriptions.csv**: Descriptions of the columns in the\nabove file\n- **template-sample-sheet-column-specifications.rds**: Column specification i.e.\ndata types expected in each column (integer, character, date)\n\nFill out the `template-sample-sheet.csv` file with your own information. Best\npractices would be to require each field to have information. Currently I have\nnot implemented hard-requirements on these columns. For right now, use your\nown judgement on what fields are necessary and should have information.\n\n### Step 2: Build a database\n\nOnce you have populated the `template-sample-sheet.csv` file, it's time to create\na *SQLite* database using the sample sheet. In the scripts directory is the\n`buildDatabase.R` script which can be used to convert the sample *CSV* file into\na *SQLite* database. It can be called like so\n\n```r\nbuildDatabase(\n  path_samplesheet = 'edited-samplesheet.csv',\n  path_col_spec_rds = 'template-sample-sheet-column-specification.rds',\n  path_db_location = 'path/to/database/output/location',\n  str_db_name = 'lab-group-DB',\n  force_overwrite = TRUE\n)\n```\n\nThe call above takes your edited sample sheet along with the column specification\n*RDS* file and builds the *SQLite* database. It will store the sample sheet in a\ntable called **mandatory_information** - this is the ID that can be used when\nquerying the database to pull out this information.\n\nIf a database by the same name exists at the output location, the command will\nstop. It's possible to overwrite the database with the same name at the output\nlocation by specifying `force_overwrite = TRUE`, which will delete the existing\ndatabase and create a new one with the new sample information.\n\n### Step 3: Moving on to running the Shiny Application\n\nNow that the database has been created, it's time to configure the Shiny app.\nto work with your custom data.\n\n## Configuring the Shiny Application\n\nIf you're using the application in its default form, there is minimal set-up\nrequired. You'll need to set two paths in the `server.R` script to get\neverything running.\n\n### Database path\n\nYou'll need to set the path to your own databse file in the following code\n\n```r\ncon \u003c- pool::dbPool(\n  drv = RSQLite::SQLite(),\n  dbname = '/path/to/your-db.sqlite'\n)\n```\n\n### Column specification path\n\nThe path to the column-specification file is also needed. The application uses\nthis object for validating incoming data. Simply change the path in the code\nbelow, also found in the `server.R` script:\n\n```r\ncol_spec \u003c- readr::read_rds('/path/to/your-column-specification.rds')\n```\n\n## Running the Application\n\nNow that we've configured the necessary files with our database information, we\ncan run the application using the following command (assuming we're in the\n`sample-management` directory):\n\n```r\n\u003e shiny::runApp('../sample-management')\n```\n\n## The Application\n\nBelow are a couple of screen shots of the application running. \n\n![Application home screen][figure_home]\n\n![Plotting the samples using their latitude and logitude][figure_map]\n\n[exampleData]: https://github.com/a-lud/sample-management/blob/main/example-data/example-set-up.R\n[figure_home]: https://github.com/a-lud/sample-management/blob/main/docs/figures/app-home.png\n[figure_map]: https://github.com/a-lud/sample-management/blob/main/docs/figures/app-plot-samples.png\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnhihin%2FsampleDB","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnhihin%2FsampleDB","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnhihin%2FsampleDB/lists"}