I have a dataframe consist of 100 samples. There are three column, one url link, second a name or a heading to the url link and third date. I want to display all those headings in shiny interface. Clicking which leads the user to the respective link page. Filter samples through selected date. But I am getting a error
Error in UseMethod: no applicable method for 'filter_' applied to an object of class "c('datatables', 'htmlwidget')" Please help
Below is the code
df$link <- paste0("<a href='", df$url, "' target='_blank'>", df$heading, "</a>")
ui <- fluidPage( dateRangeInput('dateRange',
label = 'Filter news by date',
start = as.Date('2001-01-01') , end = as.Date('2018-06-01')),
DT::dataTableOutput("table")
)
server <- function(input, output) {
output$table <- DT::renderDataTable({
DT::datatable(df[, c("link", "Date"), drop = FALSE], escape = FALSE) %>%
dplyr::filter(df$Date >= input$dateRange[1] & df$Date <= input$dateRange[2])
})
}
You are piping the result from DT::datable
to filter
, which is not a data frame-like object.
You probably want to apply filter
to the data frame and then pass the result to datatable
like this:
server <- function(input, output) {
output$table <- DT::renderDataTable({
DT::datatable(
df[, c("link", "Date"), drop = FALSE] %>%
dplyr::filter(df$Date >= input$dateRange[1] & df$Date <= input$dateRange[2]),
escape = FALSE
)
})
}