is it possible to have 2 SQL queries, and take the output of 1st of them as an input of the 2nd?
What i meant, I would like use the first SQL query, maybe smthg like this?:
rs <- dbSendQuery(con, "Select distinct X From K.Tabelle order by X asc")
data <- fetch(rs)
Therefore i could get a list of uniqe values from column X. Further I would like to use this list as a choice in selectInput("select1",...)
widget of shiny
(and it would be great if i could as well have a choice to get all of the values), which will be further used in the second/final query:
query <- reactive( sprintf("select * from K.Tabelle",
" where", input$tablename, "=", input$select1, sep="")
Is it possible? I have no idea where i should put the first query? On the server side as well?
My code:
library(ROracle)
library(shiny)
get_data <-
function(query){
on.exit(dbDisconnect(con)) ## important to close connection
con <- dbConnect(dbDriver("Oracle"),"xx",username="user",password="pwd")
dbGetQuery(con,query)
}
server <- shinyServer(
function(input, output) {
query <- reactive( sprintf("select * from K.Tabelle",
" where", input$tablename, "=", input$select1, sep="")
## simply displaying reactive inputs
output$table <- renderTable(
get_data(query())
)
})
ui_panel <-
tabPanel("Test",
sidebarLayout(
sidebarPanel(
),
mainPanel(
tableOutput("table")
)
)
)
ui <- shinyUI(navbarPage("Test",ui_panel))
runApp(list(ui=ui,server=server))
Thanks for the tipps