R에서 renderText ()로 여러 줄의 텍스트 출력 Shiny
하나의 renderText()
명령을 사용하여 여러 줄의 텍스트를 출력하고 싶습니다 . 그러나 이것은 가능하지 않은 것 같습니다. 예를 들어, 반짝이는 튜토리얼에서 우리는 다음에서 코드를 잘랐습니다 server.R
.
shinyServer(
function(input, output) {
output$text1 <- renderText({paste("You have selected", input$var)
output$text2 <- renderText({paste("You have chosen a range that goes from",
input$range[1], "to", input$range[2])})
}
)
및 코드 ui.R
:
shinyUI(pageWithSidebar(
mainPanel(textOutput("text1"),
textOutput("text2"))
))
본질적으로 두 줄을 인쇄합니다.
You have selected example
You have chosen a range that goes from example range.
이 두 줄을 결합하는 것이 가능 output$text1
하고 output$text2
하나 개의 코드 블록으로? 지금까지의 노력은 실패했습니다.
output$text = renderText({paste("You have selected ", input$var, "\n", "You have chosen a range that goes from", input$range[1], "to", input$range[2])})
누구나 아이디어가 있습니까?
당신은 사용할 수 있습니다 renderUI
및 htmlOutput
대신 renderText
과 textOutput
.
require(shiny)
runApp(list(ui = pageWithSidebar(
headerPanel("censusVis"),
sidebarPanel(
helpText("Create demographic maps with
information from the 2010 US Census."),
selectInput("var",
label = "Choose a variable to display",
choices = c("Percent White", "Percent Black",
"Percent Hispanic", "Percent Asian"),
selected = "Percent White"),
sliderInput("range",
label = "Range of interest:",
min = 0, max = 100, value = c(0, 100))
),
mainPanel(textOutput("text1"),
textOutput("text2"),
htmlOutput("text")
)
),
server = function(input, output) {
output$text1 <- renderText({paste("You have selected", input$var)})
output$text2 <- renderText({paste("You have chosen a range that goes from",
input$range[1], "to", input$range[2])})
output$text <- renderUI({
str1 <- paste("You have selected", input$var)
str2 <- paste("You have chosen a range that goes from",
input$range[1], "to", input$range[2])
HTML(paste(str1, str2, sep = '<br/>'))
})
}
)
)
<br/>
줄 바꿈 으로 사용해야 합니다. 또한 표시하려는 텍스트는 HTML 이스케이프 처리되어야하므로 HTML
함수를 사용하십시오 .
Joe Cheng 에 따르면 :
Uhhh I don't recommend using
renderUI
andhtmlOutput
[in the way that is explained in the other answer]. You are taking text that is fundamentally text, and coercing to HTML without escaping (meaning if the text just happens to include a string that contains special HTML characters, it could be parsed incorrectly).How about this instead:
textOutput("foo"),
tags$style(type="text/css", "#foo {white-space: pre-wrap;}")
(Replace the foo in #foo with the ID of your textOutput)
If you mean that you don't care for the line break:
output$text = renderText({
paste("You have selected ", input$var, ". You have chosen a range that goes
from", input$range[1], "to", input$range[2], ".")
})
'Program Tip' 카테고리의 다른 글
스타일이 %로 설정된 요소에서 너비를 픽셀 단위로 가져 오시겠습니까? (0) | 2020.12.08 |
---|---|
node.js의 require () 모듈에서 발생한 오류 처리 (0) | 2020.12.08 |
부트 스트랩에 햄버거 메뉴를 추가하는 방법 (0) | 2020.12.08 |
Chrome 확장 프로그램 hint.js 및 ngHintModules (0) | 2020.12.08 |
Spring에서 2 개 이상의 데이터베이스를 사용하는 방법은 무엇입니까? (0) | 2020.12.08 |