Rda对象和反应性在Shiny,R

时间:2015-07-15 04:29:26

标签: r shiny

我有一个图表应该由有光泽的dateInput更新。但是,我的应用程序需要在开始时加载数据。这与反应性混淆,并确保我的图表无法更新,这是我的脚本工作:

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")


}

当我把以下代码放在它上面时:

load("lastupdateemp.Rda")
load("zoomlastupdate.Rda")
load("lastupdateworkexp.Rda")

反应图无法使用数据输入进行更新。我如何克服这个问题?

0 个答案:

没有答案