Passing user input from Shiny UI to sql query

828 views
Skip to first unread message

ernest....@gmail.com

unread,
Feb 23, 2015, 8:27:22 PM2/23/15
to shinyap...@googlegroups.com

Hi all,

I am trying a simple Shiny -2- SQL connection example.

I have a UI where user enters a number (in this case ID #). Shiny then sends this to a SQL Query and then results from the Query are displayed back on the UI screen.

This is what I did so far, 

UI.r

  shinyUI(fluidPage(
    titlePanel("Test Case"),
    sidebarLayout(
      sidebarPanel((""),
             textInput("mrnnumb", "Enter ID number",""),
             submitButton("Ok")),
      mainPanel(("Results"),
         tableOutput("dis"))
)
))

server.r

 library(RODBC)
 library(sqldf)
 myconn = odbcConnect("Test1", uid="12345", pwd="password123")

 shinyServer(function(input, output) {

 a1 = reactive({input$mrnnumb})                    

 testq =  reactive({ sqlQuery(myconn, paste("select DOB,GenderCode,MaritalStatus,IDNumber from Demographics_extended where IDNumber = '",a1,"'"))})

 output$dis<-renderDataTable(testq)

 })


The results are null...nothing is happening....no error..no message...nothing....Need some help

Shiny Cool



Tareef Kawaf

unread,
Feb 24, 2015, 11:02:53 AM2/24/15
to ernest....@gmail.com, shiny-...@googlegroups.com
Hi Ernest,
This is more of a question of how shiny works.  Cross posting to shiny-discuss where it should go.
My quick look at it (and I am not an expert by any means) is that a1, and testq should be calls.  

renderDataTable(testq()) since testq is a reactive.  You can debug Shiny applications within the IDE which could help you see the flow and the value of various variables.

-Tareef

--
You received this message because you are subscribed to the Google Groups "ShinyApps Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shinyapps-use...@googlegroups.com.
To post to this group, send email to shinyap...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/shinyapps-users/2c5b19eb-f46e-4632-a23c-d5f907f586e5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages