shinyMobile
shinyMobile copied to clipboard
updateF7Slider error in unclass(x) : cannot unclass an environment
I am using an f7DatePicker that allows me to filter to a particular row in a dataset and update the value of an f7Slider input. However, I keep getting the following error and not sure what it means: error in unclass(x) : cannot unclass an environment. Not sure if this is an error specific to updateF7Slider or just some silly mistake on my end... probably the latter.
I found that it was giving me that error if I was trying to update choices, but setting value=NULL for the current value. When I changed it to value="", it fixed the issue.
I'll try this out. Thanks!
Do you have an example @ayeTown ?
observe({ updateF7Slider(session,inputId = "mood",min = 0,max = 10,value = ifelse( as.Date(as.character(input$date_1),format = "%Y-%m-%d") %in% as.Date(format(strptime(as.character(new_Data$Date), "%m/%d/%y"),"%Y-%m-%d"),"%Y-%m-%d"), new_Data[which(as.Date(format(strptime(as.character(new_Data$Date), "%m/%d/%y"),"%Y-%m-%d"),"%Y-%m-%d") == as.Date(as.character(input$date_1),format = "%Y-%m-%d")),]$Mood, 5), scale = TRUE,scaleSteps = 2,scaleSubSteps = 5 ) })
I am trying to see if for the date selected in the date input whether there is a row for this date in the dataset. If so, then update the select input value to be the value for this date (value is mood for that date).
Sorry I'm new to writing code in comments and having trouble formatting it.
The slider input is initialized with the following code...
f7Slider(inputId = "mood",label = NULL,min = 0,max = 10, value = ifelse( Sys.Date() %in% as.Date(format(strptime(as.character(new_Data$Date), "%m/%d/%y"),"%Y-%m-%d"),"%Y-%m-%d"), new_Data[which(as.Date(format(strptime(as.character(new_Data$Date), "%m/%d/%y"),"%Y-%m-%d"),"%Y-%m-%d") == Sys.Date()),]$Mood, 5 ), scale = TRUE,scaleSteps = 2,scaleSubSteps = 5)
Here is a reproducible example below...
library(shiny)
library(shinyMobile)
data <- data.frame(cbind(
"Date" = format(as.Date((as.Date(as.character(Sys.Date()),format = "%Y-%m-%d")-6):(as.Date(as.character(Sys.Date()),format = "%Y-%m-%d"))),"%m/%d/%y"),
"Value" = seq(1,7)
))
shinyApp(
ui = f7Page(
title = "My app",
f7SingleLayout(
navbar = f7Navbar(title = "updateF7Slider"),
f7Card(
f7DatePicker(inputId = "date_1",
label = NULL,
value = as.Date(as.character(Sys.Date()),format = "%Y-%m-%d"),
min = NULL,
max = NULL,
dateFormat = "m/d/yy"),
f7Slider(inputId = "value",label = NULL,min = 0,max = 10,
value = ifelse(
Sys.Date() %in% as.Date(format(strptime(as.character(data$Date), "%m/%d/%y"),"%Y-%m-%d"),"%Y-%m-%d"),
data[which(as.Date(format(strptime(as.character(data$Date), "%m/%d/%y"),"%Y-%m-%d"),"%Y-%m-%d") == Sys.Date()),]$Value,
5
),
scale = TRUE,scaleSteps = 2,scaleSubSteps = 5)
)
)
),
server = function(input, output, session) {
observeEvent(input$date_1,{
if((as.Date(as.character(input$date_1),format = "%Y-%m-%d") %in% as.Date(format(strptime(as.character(data$Date), "%m/%d/%y"),"%Y-%m-%d"),"%Y-%m-%d"))) {
new_val <- new_Data[which(as.Date(format(strptime(as.character(data$Date), "%m/%d/%y"),"%Y-%m-%d"),"%Y-%m-%d") == as.Date(as.character(input$date_1),format = "%Y-%m-%d")),]$Value
} else {
new_val <- 5
}
updateF7Slider(session,inputId = "value",min = 0,max = 10,value = new_val,
scale = TRUE,scaleSteps = 2,scaleSubSteps = 5
)
})
}
)
@ayeTown : this example does not work
Related to #108