printText <- function() {
for(i in 1:10){
Sys.sleep(0.1)
print(paste("My text", i))
y = i + 1
}
return(y)
}
I can print it with verbatimTextOutput
but I also need the returned value of y. For example,
runApp(list(
ui = shinyUI(fluidPage(
titlePanel("Print consol output"),
sidebarLayout(
sidebarPanel(actionButton("go", "Go")),
mainPanel(
verbatimTextOutput("text")
)
)
)),
server = shinyServer(function(input, output, session){
observeEvent(input$go, {
output$text <- renderPrint({
y <- printText()
})
})
})
))
The problem is that if I want to use the returned y I need to create a reactive
object, which may take me 2 times longer because I execute printText()
twice, while printing and pass to reactive
object.
How could I get the value of y and print the text onto shiny without duplicated work? Notice that I'm not gonna use progress bar because my real function is not a loop actually. I don't know how many times it may repeat. What I want is to capture the text output during the process and pass the returned value to y without creating a reactive object that causes duplicated work.
Many thanks in advance!
--
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/718b948f-89f9-4bce-9054-7ccbe6a6f049%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
printText <- function() { for(i in 1:10){ Sys.sleep(0.1)
shinyjs::html("text", paste("My text", i), add = TRUE)
y = i + 1 } return(y)}
runApp(list( ui = shinyUI(fluidPage( shinyjs::useShinyjs(),
titlePanel("Print consol output"), sidebarLayout( sidebarPanel(actionButton("go", "Go")), mainPanel(
div(id = "text")
) ) )), server = shinyServer(function(input, output, session){ observeEvent(input$go, {
shinyjs::html("text", "")
y <- printText() }) })))
paste("My text", i)