简体   繁体   中英

R shiny: transforming reactive data.frame using reactiveValues and observe

I'm having trouble transforming a reactive data.frame using reactiveValues and observe. I'm more familiar using the regular reactive() and can't quite grasp reactiveValues. I'd like to add a column called "Biomass" to the data.frame called tmp3. I'm able to transform tmp2 and add a column called "Class" and one called "Common" with no problem. A small snip of the server is below. If I try using transform to add the "Biomass" column the app wont run. I'm hoping someone could quickly glance at it and straighten me out. Let me know if providing the full code is necessary.

globals <- reactiveValues()

observe({

dat=read_lake_survey(SiteID())
surveys <- dat$result$surveys
tmp2 <- map2(surveys$fishCatchSummaries, surveys$surveyDate, ~{ 
.x$survey_date <- .y ; .x })
tmp2 <- map2(tmp2, surveys$surveyType, ~{ .x$survey_type <- .y ; .x })
tmp2 <- map2(tmp2, surveys$surveySubType, ~{ .x$survey_subtype <- .y ; .x })
tmp2 <- map2_df(tmp2, surveys$surveyID, ~{ .$survey_id <- .y ; .x })
tmp2[tmp2 == "N/A" ] <- NA 
tmp3=transform(tmp2,Class= abv$Coding[match(tmp2$species, abv$Abv)],
               FullName=abv$Common[match(tmp2$species, abv$Abv)])

  ### No luck adding this to the transform code  ######
  ### Biomass=tmp2$averageWeight*tmp2$totalCatch ###

  globals$ScrapedData=tmp3
})   

The problem was the data.frame was a tibble.

tmp2 <- data.frame(type_convert(tmp2)

does not convert it to a data.frame. I needed to use class(as.data.frame(tmp2)) After properly converted, the transform function worked fine

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM