我读过用HTML打印单独行的各种方法,但并不满意。我的目标是存储各种自变量,并将代码作为SQL语句提供,然后用户可以使用该语句在SAS中使用bin。我最终希望在我闪亮的应用程序中看到的文本是执行以下代码的结果:
binbreaks <- c(17,41,65,89,113)
x_var <- "IAG01"
for (i in 1:length(binbreaks)) {
if (i==1) {
cat(paste("select ",x_var, ", case", "\nwhen ", x_var," <= ", binbreaks[1], "then 1"))
}
if (i>1 & i<=(length(binbreaks)-1)) {
cat(paste("\nwhen ",binbreaks[i-1], " < ", x_var, " <= ", binbreaks[i], "then ", i))
}
if (i==length(binbreaks)) {
cat(paste("\nelse ", i))
cat(paste("\nend as ", x_var, "_bin"))
}在我闪亮的应用程序中产生的文本应该是:
select IAG01 , case
when IAG01 <= 17 then 1
when 17 < IAG01 <= 41 then 2
when 41 < IAG01 <= 65 then 3
when 65 < IAG01 <= 89 then 4
else 5
end as IAG01 _bin服务器。R:
shinyServer(function(input, output) {
output$SQL_pp <- renderPrint({
binbreaks<-seq(min(input_data_NA[[input$x_var]]),max(input_data_NA[[input$x_var]]),length.out=input$bins)
cat(
for (i in 1:length(binbreaks)) {
if (i==1) {
cat(paste("select ",input$x_var, ", case", "\nwhen ", input$x_var," <= ", binbreaks[1], "then 1"))
}
if (i>1 & i<=(length(binbreaks)-1)) {
cat(paste("\nwhen ",binbreaks[i-1], " < ", input$x_var, " <= ", binbreaks[i], "then ", i))
}
if (i==length(binbreaks)) {
cat(paste("\nelse ", i))
cat(paste("\nend as ", input$x_var, "_bin"))
}
}
)
})ui.R:
shinyUI(fluidPage(
navbarPage("EDA Tool",
tabPanel("SQL code", textOutput("SQL_pp"))
)
)问题是,我想打印像上面的输出。相反,我的产出看上去乱七八糟。它仍将执行,但我希望它看上去体面(即不像这样:
select IAG01 , case when IAG01 <= 17 then 1 when 17 < IAG01 <= 41 then 2 when 41 < IAG01 <= 65 then 3 when 65 < IAG01 <= 89 then 4 else 5 end as IAG01 _bin发布于 2014-07-21 22:28:55
默认情况下,HTML会忽略换行;您可以使用pre元素来保留换行和间距。代之以:
textOutput("SQL_pp")在这方面:
textOutput("SQL_pp", container = pre)https://stackoverflow.com/questions/24873961
复制相似问题