append to output?

224 views
Skip to first unread message

Adrian Duşa

unread,
Jan 26, 2015, 2:06:01 AM1/26/15
to shiny-...@googlegroups.com
Just curious... is it possible to preserve the "old" output and to append the new one?
Right now, the output gets recreated each time, but it would be nice to see the changes between two consecutive runs.

Best,
Adrian

Adrian Duşa

unread,
Jan 26, 2015, 11:31:08 AM1/26/15
to shiny-...@googlegroups.com
I think I've solved this by using capture.output() and store individual results in a global object via <<-
The million dollar question, now, is: how do I force the <pre> tag to scroll down automatically?

It would be easy using a Javascript code like:
$(".mypre").animate({ scrollTop: $('.mypre').height() }, "fast");

But can I send Javascript commands via server.R?

Thanks,
Adrian

Adrian Duşa

unread,
Jan 26, 2015, 3:51:34 PM1/26/15
to shiny-...@googlegroups.com
Got it.
For anyone needing something similar, I've simply added a custom Javascript code linked to the UI button firing the output:

$(document).ready(function(){

    $("#goButton").click(function(e){
      $('#result').animate({
        scrollTop: $('#result')[0].scrollHeight
      }, 1000);
    });

})

Works like magic.

Joe Cheng

unread,
Jan 26, 2015, 6:34:36 PM1/26/15
to Adrian Duşa, shiny-...@googlegroups.com
Cool. You can also accumulate results over time using Hadley's shinySignals package:

randomLetter <- reactive({
  invalidateLater(1000, session)
  sample(LETTERS, 1)
})

randomLetters <- shinySignals::reducePast(randomLetter, c, NULL)

This creates a randomLetters reactive whose return value is an ever-growing list of letters. I use this technique in the new "crandash" demo:



--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/shiny-discuss/57d84941-f4c1-4ede-a858-ae1f097b2785%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Adrian Duşa

unread,
Jan 27, 2015, 5:38:34 AM1/27/15
to Joe Cheng, shiny-...@googlegroups.com
Oh that's wonderful, will certainly check this out.
(glad that other people already thought about it, saves time and gives ideas).
Best,
Adrian
--
Adrian Dusa
University of Bucharest
Romanian Social Data Archive
Soseaua Panduri nr.90
050663 Bucharest sector 5
Romania

Inzirio

unread,
Nov 23, 2015, 6:31:46 AM11/23/15
to Shiny - Web Framework for R
hello, 

i'm interested in this magic trick... could you please explain me better how to link the code to the button?

it'd be great if you can create a reproducible example to use! ^^

Thank you very much!
inzirio

Adrian Dușa

unread,
Nov 23, 2015, 1:44:22 PM11/23/15
to Inzirio, Shiny - Web Framework for R
It all depends whether you want a standard shiny app or a custom one.
My application is highly customized, which means that I have a normal HTML page with a lot of Javascript code, and the example I mentioned has nothing to do with shiny, it's pure Javascript.
I could provide an example with HTML and Javascript, but I wouldn't know how to replicate that using standard shiny.

--
You received this message because you are subscribed to a topic in the Google Groups "Shiny - Web Framework for R" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/shiny-discuss/GGtKJrGUq0I/unsubscribe.
To unsubscribe from this group and all its topics, send an email to shiny-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/shiny-discuss/f5880348-7a75-4a60-a4af-1c9148aae74f%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Inzirio

unread,
Nov 23, 2015, 4:11:58 PM11/23/15
to Shiny - Web Framework for R, mioap...@gmail.com, dusa....@unibuc.ro
yes i know that it's javascript... but, i'm trying to understand how to put that javascript attached to the button using R code...

anyway, even the HTML+javascript, cause i'm noob with it, is a good example to have... you can send me a private message, if you prefer!

Thank you very much!! ^^

inzirio

Adrian Dușa

unread,
Nov 23, 2015, 4:49:53 PM11/23/15
to Inzirio, Shiny - Web Framework for R
Right, but that doesn't have anything to do with shiny, then.
It's a simple matter of defining a button with something like this, in the body:

<input id="goButton" type="button" value="clickme" />

Then use the mentioned code, in the external javascript file which needs to be mentioned in the <head> part:

$(document).ready(function(){

    $("#goButton").click(function(e){
      $('#result').animate({
        scrollTop: $('#result')[0].scrollHeight
      }, 1000);
    });

})

If you don't understand how this works, there are many examples and tutorials on W3Schools.
I hope it helps,
Adrian

Inzirio

unread,
Nov 24, 2015, 6:23:24 AM11/24/15
to Shiny - Web Framework for R, mioap...@gmail.com, dusa....@unibuc.ro
Good!
I'm wondering if there is a way to create an actionButton of a specific class in R, and then in an external CSS associate that specific javascript code...

Thank you very much! 
inzirio

Adrian Dușa

unread,
Nov 24, 2015, 7:28:57 AM11/24/15
to Inzirio, Shiny - Web Framework for R
Package htmlwidgets, perhaps?

Inzirio

unread,
Nov 24, 2015, 8:30:50 AM11/24/15
to Shiny - Web Framework for R, mioap...@gmail.com, dusa....@unibuc.ro
it seems a good way to do it!!!

I'll try! Thank you again! ^^

inzirio
Reply all
Reply to author
Forward
0 new messages