-
Notifications
You must be signed in to change notification settings - Fork 183
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Columns escaped seem false in DT::datatable( ) with many columns #691
Comments
Can the example be simpler? |
The same example but with only the second datable, without the function: options(encoding = "UTF-8")
library(DT)
library(shiny)
library(dplyr)
library(stringr)
hostipserver <- str_trim(system("hostname -I", intern=TRUE))
hostportserver <- ":8080"
app<-
shinyApp(
ui = basicPage(
navbarMenu("Bla",
tabPanel("blabla",
fluidPage(
h3("outblabla_2"),
p("toto_1 and toto_2 have to be worked urls but only toto_2 is ok"),
fluidRow(
column (12,
div(DT::dataTableOutput('outblabla_2'),
style = "font-size:80%;white-space: nowrap;width:93%")
)
)
)
)
)
),
server = function(input, output) {
blabla <- reactive({
test<-data.frame(
matrix (rep(c(c(999.2,2), 1200), 4000), nrow = 40, ncol = 30)
)
colnames(test) <- paste0("toto_", 1:30)
test<-test %>% mutate (toto_9 = ifelse (toto_9==2,TRUE,FALSE))
return( test)
})
output$outblabla_2<- DT::renderDataTable( {
mydatatable<-blabla()
mydatatable<- ( mydatatable
%>% ungroup()
%>% mutate(
nom_fichier_pdf_1='a',#paste0(gsub("\\.", "_", toto_1),'.pdf'),
nom_fichier_pdf_2='b',#paste0(gsub("\\.", "_", toto_2),'.pdf'),
toto_1_old=toto_1,
toto_1=ifelse(toto_9,paste0('<a class="url_pdf" href="http://',hostipserver ,hostportserver,'/rapportpdfpath/',nom_fichier_pdf_1,'" target = "_blank">',toto_1,'</a>'), toto_1),
toto_2_old=toto_2,
toto_2=ifelse(toto_9,paste0('<a class="url_pdf" href="http://',hostipserver ,hostportserver,'/rapportpdfpath/',nom_fichier_pdf_2,'" target = "_blank">',toto_2,'</a>'), toto_2)
)
)
escape_vector<-which(colnames(mydatatable) %in% list("toto_1","toto_2"))
print('escape 2' , paste0(escape_vector,(dput(escape_vector))))
res<-DT::datatable( mydatatable,
style = "bootstrap", class = "compact", filter='top',
selection = c("single"),
escape=escape_vector,
options = list(
deferRender = TRUE,
bSortClasses = TRUE,iDisplayLength = 5, width = "100%",
scrollX=TRUE ,
lengthMenu = list(c(5, 25, 50, 75, 100, -1), list('5', '25','50','75','100', 'All')),
search = list(
smart = TRUE,
regex = TRUE,
caseInsensitive = TRUE
)
)
);
})
})
shiny::runApp(app)
|
The solutionI don't know if you want to escape the first two columns or unescape them. The thing is what escape_vector<-which(colnames(mydatatable) %in% list("toto_1","toto_2")) to escape_vector<- -(which(colnames(mydatatable) %in% list("toto_1","toto_2")) + 1)
# notice the minus sign The reasonThe reason need to use A simpler exampletbl <-
data.frame(
a = "<a href = 'about:blank'>a</a>",
b = "<a href = 'about:blank'>b</a>",
c = "<a href = 'about:blank'>b</a>",
stringsAsFactors = FALSE
)
DT::datatable(
tbl,
# rownames = FALSE, # uncomment this line to see the differences
escape = -(which(colnames(tbl) == 'b') + 1)
) BTW, it doesn't have to be so complicated... Lines like Thanks. |
Sometimes it's not obvious to cut off, but I understand that it's more consuming time for you than for me to cut off all the unnecessary lines: I will try to be more concise next time. :) I did see that it was I miss "that the rowname is counted as 1 column" . In https://rstudio.github.io/DT/ the Thank you very much :) PS: You have a user on stackoverflow, you answer on it, or I do it ? |
Thanks. I've answered on Stackoverflow and filed two PR on the docs. |
Hello,
If I change an initial column
myCol
to an url (for example), and copy the old columnmyColInitialValue
at the end of the dataframedf
with a new name, I thought thata
which(colnames(df)=='myCol')
send back the col # ofmyColInitialValue
but It seems to be an issue in DT::datatable()Here is a reprex below and a question in Stackoverflow:
My goal is for the
escape
parameter ofDT::datatable()
. I useescape=FALSE
in waiting that. With constants it doesn't work also but the DT package seems also get the bad # column. :)Here is my source with the issue of the bad column escaped:
but I didn't get again, I didn't reproduce it.
which()
the escaped column displayed in shiny/ datatable is wrongI cannot upgrade all packages because I have qualification server and production server but not really test computer in my small company, I cannot break all.
xfun::session_info('DT')
By filing an issue to this repo, I promise that
xfun::session_info('DT')
. I have upgraded all my packages to their latest versions (e.g., R, RStudio, and R packages), and also tried the development version:remotes::install_github('rstudio/DT')
.I understand that my issue may be closed if I don't fulfill my promises.
The text was updated successfully, but these errors were encountered: