i have graph should updated dateinput in shiny. however, app requires data loaded @ start. messes reactivity, , ensures graph cannot updated, here script works:
ui <- fluidpage( #for date of update, days of unemployment dateinput("updatedate", "select date", value = "2015-06-01", min = "2015-05-20", max = "2015-07-13", format = "yyyy-mm-dd", startview = "month", weekstart = 0, language = "en"), ggvisoutput("duration") ) server <- function(input, output) { durationdata<-reactive({ selectedupdate<-with(zoomlastupdate, zoomlastupdate[(lastupdate == as.date(input$updatedate, '%y-%m-%d')),]) selectedupdate<-with(selectedupdate, selectedupdate[(unemployed == 1),]) selectedupdate<-na.omit(selectedupdate) count1<- selectedupdate[,1:2] tabcount1<- data.frame(duration=count(count1, 'spell')[,1], unemployed=count(count1, 'spell')[,2]) tabcount1 }) all_values <- function(x) { if(is.null(x)) return(null) paste0(c("duration","unemployed"), ": ", format(x)[c(1,3)], collapse = "<br />") } add_title <- function(vis, ..., x_lab = "x units",y_lab="y units", title = "plot title") { add_axis(vis, "x", title = x_lab) %>% add_axis("x", orient = "top", ticks = 0, title = title, properties = axis_props( axis = list(stroke = "white"), labels = list(fontsize = 0) ), ...) %>% add_axis("y", title=y_lab) } durationdata %>% ggvis(x=~duration, y =~unemployed, fill := "#fff8dc") %>% layer_bars(width=0.5) %>% add_tooltip(all_values, "hover") %>% add_title(title = "unemployment duration", x_lab="duration of unemployment (months)", y_lab="number of unemployed persons") %>% set_options(width = 1000, height = 600, keep_aspect = null, resizable = true) %>% bind_shiny("duration") } when put following code on top of it:
load("lastupdateemp.rda") load("zoomlastupdate.rda") load("lastupdateworkexp.rda") the reactive graph fails update data input. how overcome issue?
Comments
Post a Comment