I am learning Shiny by developing a shiny app which creates a report on chosen csv file. I was able to output dataFrame head and summary. However, I stuck with saving a str() representation of df, as str() function returns NULL, printing stuff to console instead.
Is there any workaround to save str() to variable for the purpose of representing it in the shiny app?
Saving your workspace is how you save your data within R. Click on the Console window, go to the File menu and select “Save Workspace...”. In another R session, you open this workspace with the “Load Workspace...” command. To save everything that has scrolled past on the Console window, click on the Console window.
str() function in R Language is used for compactly displaying the internal structure of a R object. It can display even the internal structure of large lists which are nested. It provides one liner output for the basic R objects letting the user know about the object and its constituents.
To display ( or print) a text with R, use either the R-command cat() or print(). Note that in each case, the text is considered by R as a script, so it should be in quotes. Note there is subtle difference between the two commands so type on your prompt help(cat) and help(print) to see the difference.
capture.output
will create a character vector (one element for each line printed to the console). If you want it in one string, you could concatenate it with paste(foo, collapse="\n")
.
data(iris)
(out <- capture.output(str(iris)))
out2 <- paste(out, collapse="\n")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With