R Shiny Widgetfunc() Warning Messages with Eventreactive(Warning 1) and Renderdatatable (Warning 2)

R shiny widgetFunc() warning messages with eventReactive(warning 1) and renderDataTable (warning 2)

You are getting this error because you are returning a DT::datatable AND you are also specifying filter='top' as one of the ... arguments to DT::renderDataTable. As the message is trying to tell you ... arguments are ignored since you are returning a DT::datatable. This is because the ... arguments are intended to be passed through to the DT:datatable constructor.

Either move filter='top' inside the DT::datatable constructor or return a data.frame and the filter='top will be used when DT::renderDataTable constructs a DT::datatable with your specified data.frame.

Warning in processWidget(instance) using renderDataTable and Shiny

rownames is not part of the arguments of DT::renderDataTable() so it is passed in ... in this function. But the documentation of DT::renderDataTable() says:

... [is] ignored when expr returns a table widget, and passed as additional arguments to datatable() when expr returns a data object

Here, you create a datatable in renderDataTable() so ... (and hence rownames = FALSE) is ignored. This argument is useless here so you can remove rownames = FALSE and it will remove the warning.

Resolving warning in as.datatable in a renderDatatable

As the warning mentions renderDataTable ignores ... arguments when expr yields a datatable object - accordingly you need to pass the ... objects directly to the datatable function or in this case to the as.datatable function:

library(shiny)
library(shinydashboard)
library(DT)
library(formattable)

custom_color_picker <- function(x) {
sapply(x, function(x) {
if (x > 0) {
formattable::csscolor("#B7D1DA", format = "hex")
} else {
formattable::csscolor("#D38591", format = "hex")
}
})
}

paddedcolor_bar <-
function(color = "lightgray",
fun = "proportion",
fun2 = "custom_color_picker",
...) {
fun <- match.fun(fun)
fun2 <- match.fun(fun2)
formatter(
"span",
style = function(x)
style(
display = "inline-block",
direction = "rtl",
"unicode-bidi" = "plaintext",
"border-radius" = "4px",
"padding-right" = "2px",
"background-color" = fun2(as.numeric(x), ...),
width = sprintf("%010.4f%%", 100 * percent(fun(
as.numeric(x), ...
)))
)
)
}

ui <- dashboardPage(dashboardHeader(),
dashboardSidebar(),
dashboardBody(DT::dataTableOutput("tabOut")))

server <- function(input, output) {

output$tabOut <- DT::renderDataTable({
tab <- data.frame(A = -5:20,
B = runif(26, 0, 10),
C = letters)
tab[, 1] <- as.numeric(tab[, 1]) # to be sure it's numerical

as.datatable(
formattable(tab,
list(
"A" = paddedcolor_bar("lightblue"),
"B" = formatter("span", x ~ sprintf("%10.2f", x))
))
# ,
# plugins = 'natural',
# options = list(columnDefs = list(
# list(type = "natural", targets = "_all")
# ))
)
}, server = FALSE)
}

shinyApp(ui, server)

Here only server is not a ... argument to renderDataTable.

R Shiny DT: How to hide columns or format table?

We can use

options= list(columnDefs = list(list(visible = FALSE, targets = target)))

to control which columns are visible, and

target <- which(names(mtcars) %in% c("gear", "carb")) - 1

to get the position of the cols. The - 1 is because js uses 0 index instead of 1 like R.

App:

library(tidyverse)
library(shiny)
library(dplyr)
library(ggplot2)
library(tidyr)
library(shinycssloaders)
library(shinythemes)
library(ggforce)
library(DT)
library(shinyWidgets)
library(shinyjs)

mtcars

ui <- fluidPage(
sidebarLayout(
sidebarPanel(
useShinyjs(),
div(
id = "form",
fluidRow(
# Button to select gear
column(
6,
pickerInput(
inputId = "gear_button", label = "Gear:", choices = c("All", unique(as.character(mtcars$gear))), options = list(`actions-box` = TRUE), multiple = FALSE
),
),
# Button to select carb ranges
column(
6,
pickerInput(inputId = "carb_button", label = "Carb:", choices = c("All", unique(as.character(mtcars$carb))), options = list(`actions-box` = TRUE), multiple = FALSE),
),
)
),
actionButton("resetAll", "Reset Filters")
),
mainPanel(
DT::dataTableOutput("table")
)
),
)

server <- function(input, output, session) {
# Explore tab - table
data <- mtcars

table <- reactive({
if (input$gear_button != "All") {
data <- data[data$gear == input$gear_button, ]
}
if (input$carb_button != "All") {
data <- data[data$carb == input$carb_button, ]
}
data
})

output$table <- DT::renderDataTable({
target <- which(names(table()) %in% c("gear", "carb")) - 1

datatable(table(),
class = "display nowrap compact",
filter = list(position = "top"),
rownames = FALSE,
options = list(
dom = "t",
columnDefs = list(list(visible = FALSE, targets = target)),
scrollX = TRUE
)
)
})

observeEvent(input$resetAll, {
reset("form")
})
}

shinyApp(ui, server)

How to change color of cells in a DT::dataTable in shiny, based on cells in another column?

Your code gives the following error:

renderDataTable ignores ... arguments when expr yields a datatable object;

Since you now return a DT::datatable object to renderDT and not a dataframe. This is a bit similar to this Q/A. So now you have to move all arguments to the DT::datatable constructor:

render_dt = function(data) {
renderDT(data)
}

and

  dt_d9 <- datatable(d9, editable = 'cell', rownames = FALSE, extensions = 'Buttons', options = list(dom = 'Bfrtip', buttons = I('colvis'))) %>% formatStyle(
'R/Y/G', 'Y', #'R/Y/G' is the column cell I'm trying to change values for based on column 'Y'
backgroundColor = styleEqual(c(0, 1), c('red', 'yellow'))
)

output$x9 = render_dt(dt_d9)

Add format to datatable conflicts with action buttons in R shiny

You should look at this answer. Applying his advice to your problem, I move escape = FALSE, selection = 'none' in datatable(df$data) and it works (you need to remove server = FALSE, which is not accepted in datatable):

    output$data <- DT::renderDataTable(
datatable(df$data, escape = FALSE, selection = 'none') %>% formatStyle(
'Motivation',
target = 'row',
backgroundColor = styleEqual(c(3), c('yellow'))
)
)

In case the answer I refer above is deleted (don't know if it can be), I also put it here:

You are getting this error because you are returning a DT::datatable AND you are also specifying filter='top' as one of the ... arguments to DT::renderDataTable. As the message is trying to tell you ... arguments are ignored since you are returning a DT::datatable. This is because the ... arguments are intended to be passed through to the DT:datatable constructor.

Either move filter='top' inside the DT::datatable constructor or return a data.frame and the filter='top will be used when DT::renderDataTable constructs a DT::datatable with your specified data.frame.

R Shiny not reading file path

The error here was in

# list of quarterly earnings worksheets
file_paths <- list.files('dashboard/data', pattern = 'xlsx', full.names = TRUE)

When the shiny app was running it was operating from the data folder as the working directory when running source("data/import_finance.R").

To accommodate simply

# list of quarterly earnings worksheets
file_paths <- list.files('data', pattern = 'xlsx', full.names = TRUE)


Related Topics



Leave a reply



Submit