r - Shiny: use server output for further input to create plot -


i have more 2 datasets various columns. datasets differ how data collected. data types/columns may same, differ among datasets. want able create 1 plot @ time data. have code selecting dataset collection frequency , selecting column/data type. have code selecting time window user may interested in, example, hour, several hours, etc. can not, though, figure out how use input time window come indices needed select appropriate rows selected column. here sample of data (i can't figure out how make following code wrap):

structure(list(`timestamp-ts` = structure(c(1432052400, 1432052700, 1432053000, 1432053300, 1432053600, 1432053900), class = c("posixct", "posixt"), tzone = ""), `record-rn` = 49178:49183, `rain_in_tot-inch` = c(0, 0, 0, 0, 0, 0), `stage-feet` = c(-0.03, -0.03, -0.03, -0.03, -0.03, -0.03), `isco_tot-` = c(0, 0, 0, 0, 0, 0)), .names = c("timestamp-ts", "record-rn", "rain_in_tot-inch", "stage-feet", "isco_tot-"), row.names = c(na, 6l), class = "data.frame") 

here code have far.

ui.r

library(shiny) library(data.table)  shinyui(fluidpage(  fluidrow( column(4, wellpanel(        helptext("to begin, select collection frequency want             view dropdown menu. 1 data type @ time available."),        selectinput("freqtype", "collection frequency", choices = c("five second",                "one minute", "five minute", "hourly"), size =4, selectize = false),        uioutput("dynamicui1"),        helptext("select dates"),       uioutput("dynamicui2"),        uioutput("dynamicui3"),        textoutput("s2")  )),  fluidrow(   wellpanel(       plotoutput("plot")))  ) ))  shinyserver( 

server.r

function(input, output, session) {     inputfreq <- reactive ({           switch (input$freqtype, "five second" = names(data.5sec), "one minute" = names(data.min),                   "five minute" = names(data.5min), "hourly" = names(data.hr))         })      inputfreq2 <<- reactive ({           switch (input$freqtype, "five second" = data.5sec, "one minute" = data.min, "five minute" = data.5min,                   "hourly" = data.hr)         })      output$dynamicui1 <- renderui ({           selectinput ("type", "select data type", choices = c(inputfreq2()[-1]))         })      output$dynamicui2 <- renderui ({           selectinput ("start", "start date", choices = (as.character(as.posixct(inputfreq2()$timestamp_ts))))         })      output$dynamicui3 <- renderui ({           selectinput ("finish", "finish date", choices = c(as.character(as.posixct(inputfreq2()$timestamp_ts))))         })      output$s2 <- rendertext({  #this here see value input$finish       paste('tim.st =', input$finish)         })      output$tim.st <- rendertext({ #and here things wonky.       which(as.character(inputfreq2()$timestamp_ts) == input$start)         })      output$tim.fi <- observe ({ #tried different when couldn't use rendertext       which(as.character(inputfreq2()$timestamp_ts) == input$finish)         })      plotoutput(outputid = c(inputfreq2()$timestamp_ts[which(inputfreq2()$timestamp_ts == input$start:input$finish)], input$type[which(inputfreq2()$timestamp_ts == input$start:input$finish)] ))            })   } ) 

my thinking take dataset selection first input, since determines data column/type , frequency time window. want data column , time window inputs via ui, don't know how ui refer output selected dataset in server. if try in ui

selectinput("fun", "func", choices = c(names(input$freqtype))), 

i get:

error: object 'input' not found 

if try

selectinput("fun", "func", choices = c(inputfreq2) 

i get:

error: operation not allowed without active reactive context. (you  tried can done inside reactive  expression or observer. 

so go renderui() , don't seem using output function correctly. code here, when run it, ui displays selection boxes inputs, plot apparently gets nan , gives message indicating or similar, depending on how tweak it.

this question seems kind of similar mine , mentions putting 1 of responses "global" , using there, don't know means.

when ui elements depend on user selection best render them on server side. able access values of input list on server side. http://shiny.rstudio.com/articles/dynamic-ui.html

oh see @ bottom have tried already. nan since nothing selected. can either set default value or before rendering plot check if values null , render if not null.


Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -