2016-04-02 26 views
1

私は各リストに文字列を含むリストオブジェクトを持ち、各リスト要素の各文字列は段落を表します。私は光沢のあるアプリケーションで結果を表示しようとしています。そこでは、各段落を別々に(新しい行を挟んで)表示できますが、これを行う方法があるかどうかはわかりません。Rでテキスト表示を書式設定する方法Shiny?

は、ここで私がこれまで持っているものです。

shinyUI(
    fluidPage(

    # Application title. 
    titlePanel("M&A Clearing House"), 

    sidebarLayout(
    sidebarPanel(
     # Copy the line below to make a text input box 
     textInput("company", label = h3("Company Name"), value = "Enter text..."), 


     selectInput("year", "Choosing Year Range", 
        choices = c("2014", "2015", "2016"), 
        selected="2015", multiple=T), 

     actionButton("submit","Submit") 
    ), 

    mainPanel(
     tabsetPanel(
     tabPanel("All results", textOutput("allresult")) 
    ) 
    ) 
) 
)) 


shinyServer(function(input, output, session) { 

# ....assuming the result generated would look like this:... 
# exampletext <- list() 
# exampletext[[1]] <- "this is a paragraph" 
# exampletext[[2]] <- "this is another paragraph" 
# exampletext ....assuming the result generated would look like this:... 

    output$allresult <- renderPrint({ 
    return(unlist(exampletext())) 
    } 
) 

}) 

答えて

3

あなたは出力したいpタグを生成するためにあなたのリスト上のlapplyを使用することができます。 UIのコードでは、これでtextOutputを置き換える:サーバーコードに

htmlOutput("allresult") 

、代わりにこれを使用する:

output$allresult <- renderUI(lapply(exampletext, tags$p)) 

はここで完全な作業例です:

library(shiny) 
shinyApp(shinyUI(
    fluidPage(
    sidebarLayout(
     sidebarPanel(), 
     mainPanel(
     tabsetPanel(
      tabPanel("All results", 
        htmlOutput("allresult")) 
     ) 
    ) 
    ) 
) 
), 
shinyServer(function(input, output) { 
    exampletext <- rep(as.list("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."), 5) 
    output$allresult <- renderUI(lapply(exampletext, tags$p)) 
})) 
関連する問題