Display Correlation table in R shiny

Hi all,

I tried to display correlation table (Val1 and Val2) with the below code. But not sure what wrong I am doing here. Request anyone help me in solving this? Below is the reprex. I am trying to display correlation table under Chart A

---
title: "Untitled"
output: 
  flexdashboard::flex_dashboard:
    orientation: columns
    vertical_layout: fill
    runtime: shiny
    
---

```{r setup, include=FALSE}
library(flexdashboard)
```

```{r}
df <- structure(list(Cat = structure(1:3, .Label = c("A", "B", "C"), class = "factor"), 
    Val1 = c(1, 4, 6), Val2 = c(4, 7, 2)), class = "data.frame", row.names = c(NA, 
-3L))
```

Column {data-width=650}
-----------------------------------------------------------------------

### Chart A

```{r}
dataTableOutput("t10")
output$t10 <- DT::renderDataTable({
  print(as.data.frame(cor(df[2:3],)))
})
```

From the documentation for Using shiny in flexdashboard, it seems you don't need to specify dataTableOutput or assign the DT table to an output object.

So your code should instead look like this:

```{r}
DT::renderDataTable({
  as.data.frame(cor(df[2:3]))
})
```
1 Like

Thanks. I am not able to get the output :slight_smile: Not sure why

It might be related to the version of the required packages.

Check if any of the required packages need updating. Other than flexdashboard, you'd want to check shiny, DT, htmlwidgets, and httpuv.

ok will check and thanks