I have created a function that returns a htmlTable, but I can't find which render and output I need to print that properly in my shiny app.
I have already tried:
- renderUI with uiOutput and with htmlOutput
- renderTable with tableOutput
- renderDataTable with dataTableOutput
The output (with renderUI and htmlOutput) in shiny is the html code for making the table not the table itself. Wrapping the htmlTable() in my function in html(), leads to no output in shiny.
UPDATE: Wrapping the htmlTable() in my function in HTML() works. Thanks everyone for all of your tips!
my_function <- function(nr_TP, nr_sus_normal, nr_FP, nr_FN, nr_sus_fraud, nr_TN){
result_table <- cbind(Normal = c("nr_TP", "nr_sus_normal", "nr_FP"), Fraud = c("nr_FN", "nr_sus_fraud", "nr_TN"))
row.names(result_table) <- c('Normal', "Suspicious", "Fraud")
where <- rbind(c(1,1), c(1,2), c(2,1), c(2,2), c(3,1), c(3,2))
style <- c('background-color: green; color: white;',
'background-color: red; color: white;',
'background-color: yellow; color: black;',
'background-color: yellow; color: black;',
'background-color: orange; color: black;',
'background-color: green; color: white;')
css.cell <- matrix('', nrow(result_table), ncol(result_table))
css.cell[where] <- style
htmlTable(result_table, css.cell = css.cell, cgroup = c("As classified by AD"),n.cgroup = c(2))}
ui <- fluidPage(
titlePanel("Test-report and correlation overview"),
sidebarLayout(
sidebarPanel(
numericInput("nr_TP",
h3("Number of Digits"),
value = 4, min = 0, max = 10),
numericInput("nr_sus_normal",
h3("Number of Digits"),
value = 4, min = 0, max = 10),
numericInput("nr_FP",
h3("Number of Digits"),
value = 4, min = 0, max = 10),
numericInput("nr_FN",
h3("Number of Digits"),
value = 4, min = 0, max = 10),
numericInput("nr_sus_fraud",
h3("Number of Digits"),
value = 4, min = 0, max = 10),
numericInput("nr_TN",
h3("Number of Digits"),
value = 4, min = 0, max = 10)
),
mainPanel(
uiOutput("performance_table"),
)
)
)
server <- function(input, output) {
output$performance_table <- renderUI({
inFile <- dataInput()
if (is.null(inFile))
{return(NULL)}
else
{
performance_table(input$nr_TP, input$nr_sus_normal, input$nr_FP, input$nr_FN, input$nr_sus_fraud, input$nr_TN)
}
}
I normally have different input and the function performance_table calculates the values on its own. But the problem is not the function, the problem is that I can't get the htmlTable displayed in my shiny. When I use a formattable (together with formattableOutput and renderFormattable I'm fine, but I want to color the different cells in different colors without using dependend formatting, and I can't get that fixed in formattable).
html()
function, and use along withrenderUI
/htmlOutput
. – Jaccar