0
for 루프의 출력을 Shiny App의 많은 렌더 출력에서 사용할 수있게하려고합니다. 간단한 문제를 만들었습니다. 각 renderPrint() 함수에는 동일한 for 루프가 있습니다. for 루프가 render *() 함수 외부로 이동되도록 코딩 할 수 있습니까?R Shiny : 많은 렌더 *() 함수에서 사용할 수있는 for 루프 출력
루프에서 반응을 사용하는 방법을 찾았지만 반대 작업에 대한 해결책을 찾지 못했습니다. 도움과 관심에 감사드립니다.
library(shiny)
ui <- fluidPage(sidebarLayout(
sidebarPanel(
numericInput(
inputId = "seed",
label = "Set seed:",
value = 1
),
numericInput(
inputId = "Number",
label = "Number:",
value = 1,
min = 1,
step = 1
)
),
mainPanel(
verbatimTextOutput("summary"),
dataTableOutput("table"),
verbatimTextOutput("data")
)
))
server <- function(input, output) {
a <- reactive({
set.seed(input$seed)
rnorm(input$Number, 2, 1)
})
b <- reactive({
5 * a()
})
rn <- reactive({
c(1:input$Number)
})
fun <- function(x, y) {
x + y
}
Table <- reactive({
data.frame(rn = rn(),
a = a(),
b = b())
})
output$table <- renderDataTable({
Table()
})
output$summary <- renderPrint({
for (i in Table()$rn) {
print (fun(Table()$a[i], Table()$b[i]))
}
})
output$data <- renderPrint({
for (i in Table()$rn) {
print (fun(Table()$a[i], Table()$b[i]))
}
})
}
shinyApp(ui = ui, server = server)