r - evaluate function in shiny and print values -


suppose have function takes input returns data frame 2 values. want render following text: value 1 df1$value1, , value 2 df1$value2. there way of doing this?

this code have right now:

## app.r ## library(shinydashboard)  ui <- dashboardpage(   dashboardheader(title = "basic dashboard"),   dashboardsidebar(),   dashboardbody(     # boxes need put in row (or column)     fluidrow(       box(rendertext(paste('value 1 is', "df1$value1"))),        box(         title = "controls",         sliderinput("slider", "x:", 1, 100, 50)       )     )   ) )  my.func <- function(x){   df1 = data.frame(value1=x*x, value2=sqrt(x))   return(df1) }  server <- function(input, output) {    output$df1 <- rendertable({     my.func(input$slider)   }) }  shinyapp(ui, server) 

thanks!

you can prepare output inside server function this:

server <- function(input, output) {     output$df1 <- renderui({         df <- my.func(input$slider)         lapply(             1:ncol(df),             function(i) {                 force(i)                 p(paste("value", i, "is", df[, i]))             }         )     }) } 

and bind in inside ui function using uioutput('df1').

alternatively can use observe block , assign specific values output in loop:

observe({     df <- my.func(input$slider)     (i in 1:ncol(df)) {         output[[paste0('value', i)]] <- rendertext({ df[, i] })      } }) 

then can use textoutput in ui textoutput('value1').


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -