I am trying to figure out how i can change type of the column after getting the data from reactive sql query...
for example when i fetch the data from database, some of the columns are characters, and i wish them to be factors. And some of the columns are numeric (which is correct) but i need them to be displayed as factors in datatable (for use in the datatable, as the column named is Tolerance, and tolerance cannot be filtered by range, it should be one single number).
Simple code:
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 rownum * from K.",input$tabnames)
dbGetQuery(con$cc, sqlInput, stringsAsFactors = T)#it hasnt worked neither
})
output$table <- DT::renderDataTable(sqlOutput(), server=TRUE, rownames=TRUE, 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))
When i have tried simply:
output$table <- DT::renderDataTable({
sqlOutput()$HOEHE_TOLP <- as.factor(sqlOutput()$HOEHE_TOLP)
datatable(sqlOutput(), server=TRUE, rownames=TRUE, filter="top", options=list(pageLength=10))})
It didnt work, and gave me an error:
Error in sqlOutput()$HOEHE_TOLP <- as.factor(sqlOutput()$HOEHE_TOLP) :
ungültige (NULL) linke Seite in Zuweisung
*invalid (NULL) left side of assignment
Any ideas how i can convert some columns to factors for reactive data frame?
Cheers