I am using a text area to put a SQL query that will fetch data and diaply in form of report using data table when I click submit button but is giving issue("Error in DT::datatable: 'data' must be 2-dimensional (e.g. data frame or matrix)
[No stack trace available]. Please let me know how it can be fixed?
library(RODBC)
library(shiny)
library(DT)
channel <-odbcConnect("ITC44407", uid="c44407", pwd="c44407")
server <-function(input, output) {
text1 <-eventReactive(input$actionButton,{req(input$caption)
getPrediction(input$caption)
})
output$text1 <-DT::renderDataTable(server = FALSE,{
DT::datatable(text1,caption = "SUBSCRIBERS REPORT CHART", filter = 'top',
extensions = c('Buttons','ColReorder'), options = list(server = FALSE,colReorder = TRUE,
dom = 'Bfrtip',
buttons =
list('pageLength','copy', 'print', list(
extend = 'collection',buttons = list(list(extend='csv',
filename = 'SubscribersData'),
list(extend='excel',
filename = 'SubscribersData'),
list(extend='pdf',
filename= 'SubscribersData')),
text = 'Download'
))))})
}
getPrediction <-function(test){
CountyResult<-sqlQuery(channel,test)
}
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
textAreaInput(inputId="caption", label="Put your SQL here", width="100%", height="400px", value="", placeholder = "SQL Placeholder"),
actionButton("actionButton", label = "Submit")
),
mainPanel(tabsetPanel(
id = 'dataset',
tabPanel("Subscribers across 20 cities", DT::dataTableOutput("text1"))
))
)
)
shinyApp(ui = ui, server = server)