I would like to build a shiny app which will allow user to choose the table name from database, and their further plotting etc. I stuck at the point of retrieving the table names from database. I cannot use the tableList which i have created using dbListTables(con,schema="K") as a choice for the selectInput widget. I do not get any error or warning, widget just does not appear at all.
My code:
library(ROracle)
library(shiny)
server <- shinyServer(
function(input, output, session) {
con <- dbConnect(dbDriver("Oracle"),"xxx/K",username="user",password="pwd")
tableList <- dbListTables(con,schema="K")
output$out <- renderPrint(tableList)
df <- data.frame()
quer <- paste("select * from K.", input$tabnames)
df <- data.frame(dbGetQuery(con, quer))
output$table <- renderTable({df})
session$onSessionEnded(function() { dbDisconnect(con) })
})
ui_panel <-
tabPanel("Test",
sidebarLayout(
sidebarPanel(
),
mainPanel(
selectInput("tabnames","tabnames", choices=as.list(tableList)),
tableOutput("out"),
tableOutput("table")
)
)
)
ui <- shinyUI(navbarPage("Test",ui_panel))
runApp(list(ui=ui,server=server))
Thanks for any tipps
[SOLVED] the part for the selectizeInput i solved by placing it on the server side:
library(ROracle)
library(shiny)
library(DT)
server <- shinyServer(
function(input, output, session) {
con <- dbConnect(dbDriver("Oracle"),"xx/K",username="user",password="pwd")
tableList <- dbListTables(con,schema="K")
updateSelectizeInput(session, "tabnames", server = TRUE, choices = tableList)
sqlOutput <- reactive({
sqlInput <- paste("select * from K.",input$tabnames)
dbGetQuery(con, sqlInput)
})
output$table <- DT::renderDataTable(sqlOutput(), server=TRUE, rownames=FALSE, filter="top", options=list(pageLength=10))
session$onSessionEnded(function() { dbDisconnect(con) })
})
ui_panel <-
tabPanel("Test",
sidebarLayout(
sidebarPanel(
),
mainPanel(
selectizeInput("tabnames",label = "server side", choices = NULL),
tableOutput("out"),
tableOutput("table")
)
)
)
ui <- shinyUI(navbarPage("Test",ui_panel))
runApp(list(ui=ui,server=server))
I additionally made the reactive SQL query.
Than i choosed the table from selectizeInput to display, [NOT SOLVED] however it shows me an error:
Error in .oci.GetQuery(conn, statement, data = data, prefetch = prefetch, :
ORA-00903: invalid table name
Than smthg has to be wrong with my SQL Query (Thanks for the tipps here!)
How its even possible if i choosed the table name from the dbListTables?
Any ideas?
dbListTables(con,schema="K")outsideshiny? - danas.zuokasdf <- data.frame(dbGetQuery(con, quer))df=reactive({dbGetQuery(con,paste0("select * from K.", input$tabnames) )})and usedf()and delete:df <- data.frame()andquer <- paste("select * from K.", input$tabnames)- Batanichekoutput$sinput=renderUI({selectInput("tabnames","tabnames", choices=as.list(tableList))})on server side and use as uioutput("sinput") on UI side - BatanichekselectizeInputchoices, however the sql query does not seem to work (I updated my question). ` sqlInput <- paste("select * from K.",input$tabnames)`, whereas K is a scheme. Thanks for additional solutions to the problem! - Mal_asqlInputbefore get it and look what bad - Batanichek