这就是我所拥有的,我认为问题在于 ui.R 首先运行,因此未定义函数 progs() (或者我不知道如何执行反应函数)。我的错误如下所示:
lapply(obj,function(val){:找不到函数“progs”中的错误
我的代码如下所示:
用户界面
library(shiny)
progs <- list.files("C:/Users/OIT-Classroom/Desktop/ODP/Report 1/aggregate/")
progs <- gsub('.{6}$', '', progs)
shinyUI(bootstrapPage(
tabsetPanel(id="Reports",
tabPanel("Report 1",
sidebarPanel(
p("text"),
radioButtons("choices", choices = progs(), label = "Programs")
),
mainPanel(
tableOutput('age')
)
),
tabPanel("Report 2",
sidebarPanel(
p("text"),
radioButtons("choices", choices = progs(), label = "Programs")
),
mainPanel(
tableOutput('psc5'),
plotOutput('psc5p'),
)
)
)
))
服务器.R
library(shiny)
shinyServer(function(input, output, session) {
progs <- reactive({
progs <- list.files(paste("C:/Users/OIT-Classroom/Desktop/ODP/", input$Reports, "/aggregate/", input$choices, ".RData", sep = ""))
gsub('.{6}$', '', progs)
})
output$age <- function(){
paste(knitr::kable(
age, format = 'html', output = FALSE,
table.attr="class='data table table-bordered table-condensed'"),
sep = '\n')
}
output$psc5 <- function(){
paste(knitr::kable(
psc5, format = 'html', output = FALSE,
table.attr="class='data table table-bordered table-condensed'"),
sep = '\n')
}
output$psc5p <- renderPlot({
plot(psc5[, 2:3], type="b", ylim=c(0, 40), ylab="", xaxt="no", xlab="", col="red", main="Figure 2: Problem Severity Comparison of Mean Scores for Children Ages 5+", cex.main=0.8, cex.axis = 0.8, font.main = 1, family="serif")
par(new = T)
axis(1, at=1:2, labels=c("Intake", "Discharge"), col.axis="black", las=1, cex.axis =0.8)
})
})