I am trying to to get min max values for a slider in R shiny. Here iswhat I have below. Based on the inputs I want to create breaks.This works when I use static values for the slider but when I use dynamic way I get this error :
non-numeric argument to binary operator
'from' must be of length 1
library(shiny)
library(shinyWidgets)
library(shinydashboard)
library(DT)
sidebar <- dashboardSidebar(
sidebarMenu(id = "tab",
menuItem("1", tabName = "1")
)
)
body <- ## Body content
dashboardBody(box(width = 12,fluidRow(
uiOutput("interaction_slider"),
DT::dataTableOutput("op")
)))
ui <- dashboardPage(dashboardHeader(title = "Scorecard"),
sidebar,
body)
# Define the server code
server <- function(input, output,session) {
df <- data.frame(month = c("mazda 3", "mazda cx5", "mazda 6","mazda miata","honda
civic","honda accord"),
april = c(9, 8, 11,14,16,1),
may = c(3,4,15,12,11, 19),
june = c(2,11,9,7,14,1))
output$interaction_slider <- renderUI({
maxkaw <- function(data) sapply(df, max, na.rm = TRUE)
minkaw <-function(data) sapply(df, min, na.rm = TRUE)
print(maxkaw)
# DOESNT WORK
sliderInput("slider","Select Range:", min = minkaw,
max = maxkaw,
value = c(minkaw,maxkaw))
})
#WORKS
# sliderInput("slider","Select Range:", min = 2,
# max = 25,
# value = c(4,7))
# })
brks <- reactive({
seq(input$slider[1], input$slider[2], length.out = 10)
})
clrs <- reactive({ round(seq(255, 175, length.out = length(brks()) - 1), 0) %>%
{paste0("rgb(",.,",", ., ",255)")}})
df_format<- reactive ({datatable(df,options = list(searching = FALSE, pageLength = 15, lengthChange = FALSE)) %>%
formatStyle(names(df),
backgroundColor = styleInterval(c(brks()), c('white', clrs() ,'white'))
)
})
output$op <-renderDataTable({
df_format()
})
}
shinyApp(ui = ui, server = server)