2

I have following dataframe in shiny which looks something like this. I am using renderDataTable to display this in shiny

  QC1     QC2     QC3
   12      23      34

I want it to be displayed like this in a tabular format

  Parameters        Resources
     QC1               12
     QC2               23
     QC3               32

I am using transpose to change it. but it is displaying only values.

Neil
  • 7,295
  • 20
  • 74
  • 127
  • You need to melt it (see `reshape2` package) in your server logic and render a table from that data frame. See also https://stackoverflow.com/questions/2185252/reshaping-data-frame-from-wide-to-long-format – Joris Meys Jul 13 '17 at 15:41

2 Answers2

2

Transpose will return you a matrix.

You will need to convert it into a data frame again.

data.frame(Parameters = rownames(t(df)), Resources = t(df))
ar7
  • 508
  • 6
  • 19
1

I think nowadays this can be done using tidyr the easiest:

library(tidyr)
df %>% gather(Parameters, Resources)
Endre
  • 670
  • 7
  • 14