DataTable embedded in R shiny app can't be edited in Safari

DataTable embedded in R shiny app can't be edited in Safari

woodwardwoodward Posts: 2Questions: 1Answers: 0

Hi first time poster. I'm using the DT library in R shiny, which is an interface to JS DataTables. My app works in Chrome, but in Safari I can't edit the cells. How do I enable that please? It also doesn't work in Edge. Here's the link.

https://woodward.shinyapps.io/7wonders/


library(shiny) library(shinythemes) library(dplyr) library(DT) library(magrittr) rnames <- c("Gears", "Tablets", "Compasses", "Sets", "Total Score") initdata <- data.frame( Number = c("1","1","1","",""), Wilds = c("","","","",""), Total = c("1","1","1","1",""), Score = c("1","1","1","7","10"), row.names=rnames, stringsAsFactors=FALSE ) ui <- fluidPage( theme=shinytheme("spacelab"), style='width:480px;', h4("7 Wonders Science Calculator"), fluidRow( column(2, actionButton("clear", "Clear")), column(10, em("Double click to enter number of symbols in column 1. "), em("Enter wilds anywhere in column 2, they will be optimised.")) ), dataTableOutput("table") ) server <- function(input, output, session){ my <- reactiveValues( data=initdata ) output$table <- renderDataTable( datatable(isolate(my$data), options = list(searching=FALSE, scrollX=FALSE, scrollY=FALSE, info=FALSE, columnDefs=list(list(className='dt-center', targets="_all")), paging=FALSE, ordering=FALSE, lengthChange=FALSE), class = "stripe nowrap cell-border", selection = "single", rownames = TRUE, escape = FALSE, editable = TRUE) ) proxy <- dataTableProxy("table") n2s <- function(n){ if_else(n==0, "", as.character(n)) } s2n <- function(s){ if_else(s %in% c("", "0"), 0, floor(abs(as.numeric(s)))) } observeEvent(input$table_cell_edit, { info = input$table_cell_edit i = info$row j = info$col k = s2n(info$value) cat("edited", i, j, k, "\n") d <- my$data if (i<=3 && j==1){ # simple symbol d[i, j] <- n2s(k) } else if (i<=3 && j==2){ # add a wild d[i, j] <- n2s(k) } # assign wilds w <- sum(s2n(d[1:3, 2]), na.rm=TRUE) cat("wilds", w, "\n") i <- 0 comb <- vector("list", (w+1)^2) for (b1 in 0:w){ for (b2 in 0:(w-b1)){ b3 <- w - b1 - b2 i <- i + 1 comb[[i]] <- c(b1, b2, b3) } } ntries <- i cat("combos", ntries, "\n") tbest <- 0 xbest <- comb[[1]] for (i in seq(ntries+1)){ if (i<=ntries){ x <- comb[[i]] } else { cat("best", xbest, "gives", tbest, "\n") x <- xbest } d[1:3, 2] <- n2s(x) d[1:3, 3] <- n2s(s2n(d[1:3, 1]) + s2n(d[1:3, 2])) # Number + Wilds d[4, 3] <- n2s(min(s2n(d[1:3, 3]))) # Sets d[1:3, 4] <- n2s(s2n(d[1:3, 3])^2) # Score for each type d[4, 4] <- n2s(s2n(d[4, 3])*7) # Score for Sets d[5, 4] <- n2s(sum(s2n(d[1:4, 4]))) # Total Score if (s2n(d[5, 4])>tbest){ tbest <- s2n(d[5, 4]) xbest <- x } } my$data <- d replaceData(proxy, my$data, resetPaging = FALSE) }) observeEvent(input$clear, { my$data <- initdata replaceData(proxy, my$data, resetPaging = FALSE) }) } shinyApp(ui, server)

Answers

  • kthorngrenkthorngren Posts: 20,264Questions: 26Answers: 4,764

    I tried with Safari (11.1 (12605.1.33.1.3)) on the Mac and it seems to be working:

    I double clicked and updated one of the cells and the Total and Score were updated. Are these the correct steps to replicate the issue?

    Do you get any console log errors when the editing doesn't work?

    I don't have Windows nor Edge so can't try that. @allan or @colin should be able to look. Please provide more details, OS version, browser version, etc so they can try replicating the issue.

    Kevin

  • woodwardwoodward Posts: 2Questions: 1Answers: 0
    edited July 2019

    Thanks Kevin!

    On Safari (on my phone iOS) the app appears fine but I can't click to edit the cells. I tried double tap, tap and hold, hold etc but nothing works.

    Actually it works for me on Chrome and Edge. I haven't tried any other browsers.

  • shrektanshrektan Posts: 9Questions: 1Answers: 0

    @woodward I think you are using the editing function of the DT package. However, this functionality is not provided by datatables officially. I mean, it's not the same thing as the official Edit extension as the later is not for free. So you should post the issue on rstudio/DT instead of here.

This discussion has been closed.