title: How to update database connection in Rstudio global environment via shiny app
body: <p>I have the <code>shiny</code> app below in which when I give the password and press the actionbutton I want to see that the connection is established in my Rstudio global environment like when I attempt it manually, outside of the shiny app environment (in the upper right corner box that includes all global environment ojects in Rstudio). I have created an <code>app</code> file and a <code>global</code> file for this reason. When I do this I have to use that <code>con</code> connection in order to process the data and also update all the objects I create based on this connection.</p>
  <p><strong>app.r</strong></p>
  <pre><code>library(shiny)
  library(shinydashboard)
  library(shinydashboardPlus)
  library(shinyjs)
  mytitle &lt;- paste0(&quot;Life, Death &amp; Statins&quot;)
  dbHeader &lt;- dashboardHeaderPlus(
    titleWidth = &quot;0px&quot;
  )
  
  
  shinyApp(
    ui = dashboardPagePlus(
      header = dbHeader,
      sidebar = dashboardSidebar(width = &quot;0px&quot;
      ),
      body = dashboardBody(
        
        useShinyjs(),
        tags$script(HTML(&quot;$('body').addClass('fixed');&quot;)),
        
        tags$head(tags$style(&quot;.skin-blue .main-header .logo { padding: 0px;}&quot;)),
        passwordInput(&quot;pwd&quot;,label = &quot;&quot;,value = &quot;&quot;,width = &quot;100%&quot; ),
        actionButton('button', &quot;Continue&quot;),
      )
      
      
    ),
    server&lt;-shinyServer(function(input, output,session) { 
      hide(selector = &quot;body &gt; div &gt; header &gt; nav &gt; a&quot;)
      
    }
    )
  )
  </code></pre>
  <p><strong>global.r</strong></p>
  <pre><code>library(odbc) 
  con&lt;- dbConnect(odbc(),
                  driver   = &quot;SQL Server&quot;,
                  database = &quot;databasename&quot;,
                  server   = svr,
                  port     = 1433,
                  UID      = &quot;uid&quot;,
                  PWD      = input$pwd)
  practicename&lt;-dbGetQuery(con,&quot;select practicename from practice&quot;)[1,1]
  year&lt;-75
  sqlo&lt;- &quot;select count(extractionoptout)
  from patients where extractionoptout=1
  and getdate()&gt;dateadd(year,75,dob)&quot;
  
  
  tm&lt;-data.table(dbGetQuery(con,sqlm))
  </code></pre>