How to nicely(!) show files seen by a shiny app

Hi there!
I have a shiny app that saves some files to the temporary storage before they are zipped and downloaded. I want to show which files are present, in a nice way, e.g. with a textoutput or verbatimtextoutput, preferentially based on the saved files, or alternatively by tracking the state upon the clicks that generate the files.
However, I'd like to make the output a bit nicer, e.g. by adding linebreaks or some other text styling (bullet points) to increase readability.
Any ideas??

library(shiny)
library(stringr)

# Define UI for application
ui <- fluidPage(
    titlePanel("FileTest"),

    # Sidebar
    sidebarLayout(
        sidebarPanel(
            h4("These are the files found by the app:"),
            textOutput("File_List") 
            ),
     # MainPanel
     mainPanel( )
    )
)

# Define server logic 
server <- function(input, output) {

 # save some dummy files
    write.csv(iris, "File 1.csv")
    write.csv(iris, "File 2.csv")
    write.csv(iris, "File 3.csv")
    write.csv(iris, "File 4.csv")

# Retrieve list of saved files 
  File_List = reactive({  
     saved_files = list.files(pattern = "\\.csv")
     saved_files = str_remove(saved_files, "\\.csv")
    })
  
 output$File_List = renderText( File_List() )
}

# Run the application 
shinyApp(ui = ui, server = server)

the unicode for bullet point is U+2022 which in R syntax would be \U2022

cat("\U2022Hello\n\U2022World")
•Hello
•World

Hmm, cool, but how can I successfully merge this to the vector of files I have?

adding a cat() to rendertext seem to print text in the console output but not in the app...

adding "paste("\U2022", saved_files, "\n")" into the File_List() adds the dots (at least) but no line breaks.

Here is an example I came up with; I use uiOutput/renderUI; and the whitespace is set by styling the parent div


library(shiny)

ui <- fluidPage(
  div(style="white-space: break-spaces;",
      uiOutput("tout"))
)

server <- function(input, output, session) {
  File_list <- reactive(paste0(letters[1:10],".csv"))
  
  output$tout <- renderUI({
    paste0("\u2022",req(File_list()), collapse = "\n")
  })
}

shinyApp(ui, server)

Thanks for the bullet point tip, also the renderUI tip works.

In between I figured out, cat() (or glue) can be used when replacing renderText with renderPrint.
This however requires to put the output into a verbatimTextOutput.
So I use this strategy now and define the styling of the verbatimTextOutput so it looks a bit more consistent with the rest of the app.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.