{"id":14066963,"url":"https://github.com/AndreAlz/Directory","last_synced_at":"2025-07-30T00:31:56.435Z","repository":{"id":202058427,"uuid":"149151947","full_name":"AndreAlz/Directory","owner":"AndreAlz","description":"This repository is based in \"R Shiny\" with a connection to a MySql Database and an option to upload Excel files to bulk inserts.","archived":false,"fork":false,"pushed_at":"2018-09-24T17:06:40.000Z","size":46,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-12-04T07:36:20.983Z","etag":null,"topics":["excelreader","mysql","mysql-database","r","shiny","shiny-apps"],"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/AndreAlz.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}},"created_at":"2018-09-17T16:04:42.000Z","updated_at":"2022-03-11T02:29:07.000Z","dependencies_parsed_at":null,"dependency_job_id":"2a8a77c2-1b42-42da-bb19-6e6b089621cc","html_url":"https://github.com/AndreAlz/Directory","commit_stats":null,"previous_names":["andrealz/directory"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/AndreAlz/Directory","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AndreAlz%2FDirectory","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AndreAlz%2FDirectory/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AndreAlz%2FDirectory/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AndreAlz%2FDirectory/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AndreAlz","download_url":"https://codeload.github.com/AndreAlz/Directory/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AndreAlz%2FDirectory/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":["excelreader","mysql","mysql-database","r","shiny","shiny-apps"],"created_at":"2024-08-13T07:05:21.294Z","updated_at":"2025-07-30T00:31:56.155Z","avatar_url":"https://github.com/AndreAlz.png","language":"R","readme":"# Directory\n\n## Introduction\nThis app was built to control the differents *annexes* we have in a contact center, improving their **search**, **control** and **management**.\nTo understand how Shiny works in general, you have to understand the concept of a different paradigm, **reactive programming**.\n\n\u003e Reactive programming is a subset of asynchronous programming and a paradigm where the availability of new information drives the logic forward rather than having control flow driven by a thread-of-execution.\n\u003e- Jonas Bonér and Viktor Klang, [Reactive Programming vs. Reactive Systems](https://www.oreilly.com/ideas/reactive-programming-vs-reactive-systems)\n\nThe reactivity and data flow of this repository is showed in this simple map:\n\n![Reactivity Map](https://user-images.githubusercontent.com/31576039/45839122-11f51680-bcd9-11e8-9e41-f906d103aa4f.png)\n\nThis is an example of how the Shiny app looks like in the end:\n\n![Overview](https://user-images.githubusercontent.com/31576039/45829616-f847d500-bcc0-11e8-9883-ce55a82eb261.png)\n\n## Libraries\nI am using the following libraries in *server.R*:\n\nLibrary | Usage | Documentation\n------- | ----- | -------------\nDBI | Connection to the DB, sending queries and catching resultant information | [DBI package R](https://www.rdocumentation.org/packages/DBI/versions/0.5-1)\nRMySQL | Driver for the connection | [RMySQL package R](https://www.rdocumentation.org/packages/RMySQL/versions/0.10.15)\nDT | Select row in the datatable rendered by Shiny | [DT package R](https://www.rdocumentation.org/packages/DT/versions/0.4)\ndata.table | Better management of the information uploaded in an Excel file | [data.table package R](https://www.rdocumentation.org/packages/data.table/versions/1.11.6)\nreadxl | Read and save the Excel file uploaded even though it is a 'xls' or 'xlsx' | [readxl package R](https://www.rdocumentation.org/packages/readxl/versions/1.1.0)\nStringr | Creating a query to insert all the information from the Excel(found it in [here](https://user-images.githubusercontent.com/31576039/45834019-c425e180-bccb-11e8-9321-04dc81f1d093.png)) | [Stringr package R](https://www.rdocumentation.org/packages/stringr/versions/1.3.1)\n\n## Functions\nWe use three simple functions to create connection with the Database, simulate clicking a button with JS and avoiding all the existing data in the dataset uploaded on the page:\n\n### Connection with the Database\n```R\nconnectMySQL\u003c-function(){\n  m = dbDriver(\"MySQL\")\n  myHost \u003c- \"YOUR IPP\"\n  myUsername = \"USER\"\n  myDbname = \"DBNAME\"\n  myPort = \"PORT\"\n  myPassword = \"PASSWORD\"\n  con = dbConnect(m, user= myUsername, host= myHost, password= myPassword, dbname= myDbname, port= myPort)\n  return(con)\n  }\n```\n\n### Simulation of clicking a button\n```javascript\njQuery(document).ready(function(){\n  jQuery('#nombre').keypress(function(evt){\n    if (evt.keyCode == 13){\n      jQuery('#bnombre').click();\n    }\n  });\n});\n```\n\n### Avoiding duplicates\n```R\ndepurar\u003c-function(fileb,conne){\n  duplicados=matrix(nrow = 0, ncol = 6)\n  conn=conne\n  consultaquery=\"select anexo from catalogo\"\n  filei=t(as.numeric(unlist(fileb[,3])));\n  i=1\n  flag=0\n  for (i in i:length(filei)) {\n    resu = dbSendQuery(conn, consultaquery)\n    sqlb = dbFetch(resu,n=-1)\n    j=1\n    for (j in j:length(sqlb[,1])) {\n      if(toString(filei[1,i])==toString(sqlb[j,1])){\n        duplicados=rbind(duplicados,fileb[i,])\n        flag=1\n        break\n      }}\n      if(flag==0){\n        consulta1=\"insert into catalogo(nombre, campa, anexo, cel, sede,cargo) value ('\"\n        consulta2=\"', '\"\n        consulta3=\"')\"\n        query=paste(consulta1,\n                            fileb[i,1],consulta2,fileb[i,2],\n                            consulta2,fileb[i,3],consulta2,fileb[i,4],\n                            consulta2,fileb[i,5],consulta2,fileb[i,6],\n                            consulta3,sep = \"\")\n        res=dbSendQuery(conn,query)\n        dbClearResult(res)\n      }else{\n        flag=0\n      }\n    dbClearResult(resu)\n  }\n  return(duplicados)\n}\n```\n\n## UI\nThe *ui.R* file it just used to render the different views in the webpage, as you can see in the following code:\n```R\nlibrary(shiny)\nshinyUI(bootstrapPage(\n    uiOutput(\"login\"),\n    uiOutput(\"admin\"),\n    uiOutput(\"usr\")\n  )\n)\n```\nAs you can see there are four lines of code because we are rendering all the information and functions of the webpage in the *server.R* file.\n\n## Server\nIn *server.R* you will find all the libraries to be used and the _*.R_ files with different funcions:\n```R\nlibrary(shiny)\nlibrary(DBI)\nlibrary(RMySQL)\nlibrary(DT)\nlibrary(data.table)\nlibrary(readxl)\nlibrary(stringr)\nsource(\"conect.R\")\nsource(\"depurar.R\")\n```\n### Main Login\nThis function will be show as the first view for the user. Its important to say that the *actionButton called \"entrar\"* will be observe for **login admin** and **login user**.\n```R\noutput$login=renderUI({\n    fluidPage(\n      includeScript(\"entre.js\"),\n      mainPanel(\n        titlePanel(\"DIRECTORIO DE ANEXOS\"),\n        textInput(\"usuario\", \"USUARIO\"),\n        passwordInput(\"pw\", \"CLAVE\"),\n        actionButton(\"entrar\", \"ENTRAR\")\n      ))\n  })\n  ```\n### Admin and User Login\nThis function react to the changes on the values of [Main Login](https://github.com/AndreAlz/Directory/blob/master/README.md#main-login)\n  ```R\n   observeEvent(input$entrar,{\n    output$admin=renderUI({\n      if (toString(input$usuario)==\"admin\" \u0026\u0026 toString(input$pw)==\"mdy12345\") {...}\n      \n   observeEvent(input$entrar,{\n    output$usr=renderUI({\n      if (toString(input$usuario)==\"mdyuser\" \u0026\u0026 toString(input$pw)==\"12345\") {...}\n  ```\nWhat we do is see if the user and the password are correct, if it so we would show differents views of the same web page with a different amount of functionalities. Actually, the admin user would have all the functionalities like **search**, **delete**, **insert** and **B¿bulk insert**, while the normal user just have the option to **search** and **show** the information.\n\n#### Bulk Insertion\nThe function of bulk insertion is only available for the admin user as we said before, and for me is the most interesting function here we see its logic:\n```R\nobserveEvent(input$afirmaM,{\n    if (tabledata!=0) {\n      tabledata[,1][is.na(tabledata[,1])]\u003c-\"--\"\n      tabledata[,2][is.na(tabledata[,2])]\u003c-\"--\"\n      tabledata[,4][is.na(tabledata[,4])]\u003c-\"--\"\n      tabledata[,5][is.na(tabledata[,5])]\u003c-\"--\"\n      tabledata[,6][is.na(tabledata[,6])]\u003c-\"--\"\n      conn=connectMySQL()\n      duplicados=depurar(tabledata,conn)\n      output$resultado=DT::renderDataTable({\n        duplicados\n      })\n      tabledata\u003c\u003c-0\n    }\n  })\n```\n","funding_links":[],"categories":["R"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FAndreAlz%2FDirectory","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FAndreAlz%2FDirectory","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FAndreAlz%2FDirectory/lists"}