How to get date range within UI.R to update every day (Shiny Server)

808 views
Skip to first unread message

Ben Shoemaker

unread,
Apr 3, 2013, 3:50:29 PM4/3/13
to shiny-...@googlegroups.com
I've got the following code:

dateRange = rev(seq(as.Date("2013-03-12"), Sys.Date()-1, by = 1))

shinyUI(pageWithSidebar(

  headerPanel("..."),

  sidebarPanel(
    selectInput("startDate", "Start Date:", c(dateRange)),

    selectInput("endDate", "End Date:", c(dateRange)),


This process runs on a server using Shiny Server, and it runs continuously. As I understand it, unless UI.R is changed in some way, it won't be updated, meaning that the dateRange variable won't update and display the most recent dates as time goes by. I want this variable to update as it changes, meaning that as soon as "Sys.Date()-1" changes from say, "2013-04-02" to "2013-04-03", I want the UI to change with it. Can anybody help out with this? Thank you

Ben

Davïd Żbik

unread,
Apr 3, 2013, 5:45:24 PM4/3/13
to shiny-...@googlegroups.com
You need a timeout function which is triggered once a day. Why don't you use setInterval() in JavaScript on the client to send an input to the server at midnight? Then use a reactiveUI which reacts to this input to update the client.

Or better yet, do it all in the browser on the client side.
 




Ben

--
You received this message because you are subscribed to the Google Groups "Shiny - Web Framework for R" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discus...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Tim Abraham

unread,
Aug 19, 2013, 4:37:13 PM8/19/13
to shiny-...@googlegroups.com
Dovid, can you share a code example of how one would do this? 

Marianne Corvellec

unread,
Aug 27, 2013, 5:15:30 PM8/27/13
to shiny-...@googlegroups.com
Dear all,

I guess I'm trying to do the same thing.

I went for the function renderUI in server.R and the function uiOutput in ui.R...
I get an error though, which seems to be specific to dateInput (selectInput would work fine).

So in server.R, I define:

output$select_date <- renderUI({
    dateInput("date",
              label = "Date",
              value = Sys.Date(),
              min = "2013-01-01",
              max = Sys.Date())
})


and in ui.R, I call:

uiOutput("select_date")

Later in server.R, I want to use input$date, well, as.character(input$date), but then I get Error: 'getCharCE' must be called on a CHARSXP :(

Has anyone found a workaround for this?

Thanks in advance!

Marianne

Winston Chang

unread,
Aug 27, 2013, 5:41:17 PM8/27/13
to shiny-...@googlegroups.com
Hm, that's strange. Can you post the output of sessionInfo() on your system?

-Winston

Marianne Corvellec

unread,
Aug 28, 2013, 9:51:51 AM8/28/13
to shiny-...@googlegroups.com
Hi Winston,

Sure -- it's the same output as last time I posted ;)

> sessionInfo()
R version 3.0.1 (2013-05-16)
Platform: x86_64-pc-linux-gnu (64-bit)

locale:
 [1] LC_CTYPE=en_US       LC_NUMERIC=C         LC_TIME=en_US      
 [4] LC_COLLATE=en_US     LC_MONETARY=en_US    LC_MESSAGES=en_US  
 [7] LC_PAPER=C           LC_NAME=C            LC_ADDRESS=C       
[10] LC_TELEPHONE=C       LC_MEASUREMENT=en_US LC_IDENTIFICATION=C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

Thanks!
Marianne
Reply all
Reply to author
Forward
0 new messages