0

I want to print the content of the writeLines in new lines but I am not being able to in my Shiny app. The relevant server code is attached. The text in the box is coming out as if it is concatenated and not in new lines. Can someone please help me?

Updated Reproducible Example

shinyUI(dashboardPage( skin = "black",
                       dashboardHeader(title = "Fruits",titleWidth = 450),
                       dashboardSidebar(width=250,tags$head(
                         tags$style(HTML("
                      .sidebar { height: 90vh; overflow-y: auto; font-size: 17px;}
                      " )
                         )
                       ),
                       
                       sidebarMenu(
                         
                         menuItem("Fruits", tabName = "Fruits"),
                         fileInput("file","Upload file (.xlsx)", multiple = TRUE,accept = c(".xlsx")),
                         
                         uiOutput("selectfile"),
                         
                       )),
                       dashboardBody(
                         tabItems(
                           
                           tabItem(tabName = "Fruits",
                                   fluidPage(
                                     
                                     uiOutput("tb")
                                     
                                     
                                   )
                                   
                           )))))


shinyServer(function(input, output, session)
{
  fruits <- reactive({
    req(input$file)
    inFile <- input$file
    if(is.null(inFile))
      return(NULL)
    
    fruits<-read_excel(paste(inFile$datapath, ".xlsx", sep=""), sheet = 1)
    
  })
  
  data <- reactive({
    data<-data.frame(fruits())
  })
  
  
  output$text1<- renderPrint({
    for(i in 1:length(data()$fruit_column)){
      writeLines(paste("Fruit", i ,"is", data()[i,fruit_column]))
    }
  })
  
  output$tb <- renderUI({
    if(is.null(input$file)) {return()}
    else
      tabsetPanel(
        
        tabPanel("Tab 1", 
                 box( title = "Fruit Log", status = "primary", solidHeader = TRUE,
                      collapsible = TRUE,
                      textOutput("text1")))
      )
  })
  })

shinyApp(ui, server)

This should give a rough idea of the app I have created although this reproducible example might have errors

Nil_07
  • 106
  • 1
  • 8
  • How did you define `output$text1` in the UI? Remember that you are writing HTML and HTML doesn't use new-line character for new lines. It uses special HTML element like ` ` for line breaks. It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input that can be used to test and verify possible solutions. – MrFlick Jun 21 '21 at 20:23
  • Hi! As you can see in the example, I am defining a textOutput with id "text1" in renderUI in the server. As for a reproducible example, the ui part doesn't have anything to do with this. I feel this is a good enough reproducible example to understand the problem. Anyway, I have updated the reproducible example. As an input to the app, one can create a simple .xlsx file with a column called fruit column and populate it with random fruit names. The reproducible example might have some errors. The basic problem is to get the fruit names printed in new lines every time. – Nil_07 Jun 21 '21 at 21:18
  • verbatimTextOutput seems to solve the issue! – Nil_07 Jun 21 '21 at 21:27

0 Answers0