2
votes

Unfortunately I can't use my actual data.frame since it is not mine and is copyrighted, but I will try to explain as best as I can

I have a data.frame that contains a column with unique strings. when I do datatable(mydf) in the Rstudio console, it shows me the correct table in viewer. However, when I do the same in shiny I get this warning:

Warning in [<-.data.frame(*tmp*, , j, value = list("ECDTM-12 Trimmed eTAG truncated after Fn F232C No Stop CRLF2 transcript variant 1 NM_022148_3", : provided 10 variables to replace 1 variables

essentially what it does is it takes the first string in that column "ECDTM-12 Trimmed eTAG truncated after Fn F232C No Stop CRLF2 transcript variant 1 NM_022148_3" and overrides every other string in that row with this string, instead of showing what those rows actually contain

some maybe helpful code:

library(shiny)
library(shinythemes)
library(shinycssloaders)
library(dplyr)
library(readr)
library(xlsx)
library(openxlsx)
library(ggplot2)
library(reshape2)
library(ggthemes)
library(DT)
set.seed(1)

code in the UI function:

fluidRow(column(12, align="center", withSpinner(dataTableOutput("partTables")

code in the server function:

Lib_P1_P2 <- reactive(if(LibName() == "1.1A" | LibName() == "1.1B" | LibName() == "2.1"){readRDS(paste0("data/",input$library," P1_P2.rds"))})    
output$partTables <- renderDataTable({
    datatable(Lib_P1_P2(),options=list(pagelength=10), rownames = FALSE, escape = FALSE) 
})

I added set.seed(1) and escape=FALSE after I saw this question: R Shiny renderDataTable issue but that didn't work either..

If I've left out any important info, let me know I'd be happy to provide. I'm new to stackoverflow so excuse my newbie-ness.

1
Try having renderDataTable() return your data.frame directly, rather than passing it through Datatable first. The shiny example of integrating with data tables does this.Artem Sokolov
that shows me the right table, with the right rows now, but the reason I was using datatable was for the options, like having the pagelength set to 10... so you think the problem is the way datatable is reading my data.frame?Beeba
Replace renderDataTable with DT::renderDataTable and dataTableOutput with DT::dataTableOutput to make sure the correct namespace is used. These functions also exist in the shiny packageGregor de Cillia
Adding DT:: caused my rows to be the same againBeeba
What do you mean "the same again"? DT::renderDataTable({datatable(...)}) should give you almost the same table as in the RStudio console.Gregor de Cillia

1 Answers

2
votes

I figured out the reason!! The whole table was a dataframe except for that last column which was apparently a list, I had to unlist it and it worked after that