{"id":18380851,"url":"https://github.com/eeholmes/simplesqlliteapp","last_synced_at":"2025-08-31T22:43:42.444Z","repository":{"id":44641820,"uuid":"135510017","full_name":"eeholmes/SimpleSQLliteApp","owner":"eeholmes","description":"Simple shiny app to intereact with a SQLlite database","archived":false,"fork":false,"pushed_at":"2022-02-02T18:06:32.000Z","size":24,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-11T20:32:20.841Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"cc0-1.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/eeholmes.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-05-31T00:10:34.000Z","updated_at":"2022-02-02T18:04:56.000Z","dependencies_parsed_at":"2022-09-13T19:01:03.357Z","dependency_job_id":null,"html_url":"https://github.com/eeholmes/SimpleSQLliteApp","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/eeholmes/SimpleSQLliteApp","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eeholmes%2FSimpleSQLliteApp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eeholmes%2FSimpleSQLliteApp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eeholmes%2FSimpleSQLliteApp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eeholmes%2FSimpleSQLliteApp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eeholmes","download_url":"https://codeload.github.com/eeholmes/SimpleSQLliteApp/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eeholmes%2FSimpleSQLliteApp/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273051867,"owners_count":25037078,"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-08-31T02:00:09.071Z","response_time":79,"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":[],"created_at":"2024-11-06T00:43:47.108Z","updated_at":"2025-08-31T22:43:42.414Z","avatar_url":"https://github.com/eeholmes.png","language":"R","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SimpleSQLliteApp\n\nThis is a super simple app that shows how to link a SQLlite database to a shiny app.  SQLlite is installed on shinyapps.io\nso if you use that to deliver apps, then you are set.  \n\n## How to run the app\n\nInstall the sqldf package.  That'll install SQLlite.  You do not have to install anything else for the database part.  Install the shiny package.  The app uses also uses ggplot2 and stargazer packages, so install those too.\n\nSave the 2 files somewhere and set your working directory to whatever directory those files are in.  Open up `app.R` in RStudio.  You should see a **Run App** link at the top of the file.  Click that and it should run.  \n\n## Sharing a shiny app with other people\n\nYou can use RStudio's https://www.shinyapps.io/ service for free.  Make an account.  Then click on Dashboard and it'll walk you through how to connect your account to RStudio.\n\n## Why use a database?\n\nBecause your dataset  is really huge and you do\nwant to load that into your R session.  In my simple tests, querying a SQLlite database was not slower than having the whole dataset\nin memory.  Another reason would be if you want to have your database somewhere other than local.  Maybe you want to host your \ndatabase on Amazon (say) and be able to query it from many different apps or from a browser.  If you need to query your database often in your app, that hosting remotely might add a lot of overhead.\n\nHow to set up a SQLlite database?  Super easy. Make sure you do this in the same directory as you shiny app (or if not just add \nthe right path to whereever you store the database file).\n\n## Create database from csv file\n```\nlibrary(sqldf)\ndb \u003c- dbConnect(SQLite(), dbname=\"database.db\")\nwrite.csv(mtcars, file=\"mtcars.csv\", quote=FALSE)\ndbWriteTable(conn=db, name=\"data\", value=\"mtcars.csv\", row.names=FALSE, header=TRUE,overwrite=TRUE)\ndbDisconnect(db)\n```\nObviously do not use `overwrite=TRUE` if you want to add data to an existing database.  `name` is the name of the table in your \ndatabase.  You can many different tables in one database.  In fact, that is normally how databases are used (information is spread\nacross multiple tables).  In R, that would not be good and you'd use some package to put everything together in one huge data.frame\nwith all the info duplicated as needed.\n\n## Create database from data.frame\n```\nlibrary(sqldf)\ndb \u003c- dbConnect(SQLite(), dbname=\"database.db\")\nwrite.csv(mtcars, file=\"mtcars.csv\")\ndbWriteTable(conn=db, name=\"data\", value=mtcars, row.names=TRUE, header=TRUE,overwrite=TRUE)dbDisconnect(db)\n```\n\n## Getting info out of your database\n\nAgain super easy.\n\n```\n    sqldf(\"select mpg from data\", dbname=\"database.db\")\n```\n`data` here is the name that I gave the `mtcars` table in the `database.db`.\n\nIn a shiny app, you will want to create a query string from variables.  \n```\n    cyl=c(4,6)\n    carb=1\n    query \u003c- paste0(\"select mpg, wt from data \",\n                    \"where cyl in ( \",  paste(cyl, collapse=\", \"),\" )\",\n                    \" and carb=\",carb)\n    sqldf(query, dbname=\"database.db\")\n```\nSearch online for tutorials on SQLlite query syntax.  The basics are pretty easy.  The complicated is quite complicated but\nsimple is dead easy.  Be careful about quotes in your csv file.  `write.csv()` will put quotes around your text by default and\nthat will make it a real pain to write queries since you have to add `\\\"` everywhere.  So use `quote=FALSE` to stop that.\n\nNote there are a few different packages you can use to interact with your database.  I used `sqldf` and its functions because\nit was the easy.  Some people have had trouble with `dbWriteTable()` function.  `sqldf` has another one you can use (google it). \nBut I had trouble with that and `dbWriteTable()` worked fine.\n\n## References\n\nThe following are online tutorials that I used to get started.  \nThere are 3 different methods for getting a csv file into a SQLlite database in these links.  I chose the one I did since it worked seamlessly for me.\n\n\nhttps://www.r-bloggers.com/r-and-sqlite-part-1/amp/\n\nhttp://tiffanytimbers.com/querying-sqlite-databases-from-r/\n\nhttp://tiffanytimbers.com/building-a-basic-database-from-csv-files-using-sqlite3/\n\nhttps://www.tutorialspoint.com/sqlite/sqlite_where_clause.htm\n\nhttps://shiny.rstudio.com/articles/persistent-data-storage.html#sqlite\n\n\n## Reuse statement\n\nReuse and adapt this repo however you want. Attribution is great, like I did in references, but not required. License: CC0 1.0 Universal\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feeholmes%2Fsimplesqlliteapp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feeholmes%2Fsimplesqlliteapp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feeholmes%2Fsimplesqlliteapp/lists"}