我正在尝试使用对renderText函数的两个连续调用在主页中打印两行反应值。我现在只看到第二个值。
如果删除第二个renderText函数,程序会愉快地打印第一个值,但是如果我将第二个renderText函数返回给代码,则不会打印第一个值,第二个值是。
我想要的是显示两个反应值(灵敏度和特异性)的主页;一旦这个工作,那么我会抛出一些额外的情节。
这是错误的render *函数,还是错误的pageWithSidebar()函数?
以下是UI.R和server.R文件。
#ui.R
library(shiny)
# Define UI for application that draws a histogram
shinyUI(pageWithSidebar(
headerPanel("Header"),
mainPanel("Main"),
# Sidebar with a slider input for the number of bins
sidebarLayout(
sidebarPanel(
sliderInput("sensitivity",
"Sensitivity",
min = 0.0,
max = 1.0,
value = 0.8),
sliderInput("specificity",
"Specificity",
min = 0.0,
max = 1.0,
value = 0.4)
),
# Show a plot of the generated distribution
mainPanel({
textOutput("caption1")
textOutput("caption2")
})
)
)
)
and server.R
#server.R
library(shiny)
shinyServer(function(input, output) {
output$caption1 <- renderText(input$sensitivity)
output$caption2 <- renderText(input$specificity)
}
)
答案 0 :(得分:1)
您对mainPanel()
的调用中的语法略有偏差。
要解决此问题,请使用此
# Show a plot of the generated distribution
mainPanel(
textOutput("caption1"),
textOutput("caption2")
)
而不是
# Show a plot of the generated distribution
mainPanel({
textOutput("caption1")
textOutput("caption2")
})
您的版本存在的问题是,在R中,只要计算括在括号中的表达式,就只返回其中最后一个语句的结果。您可以通过尝试以下方式看到更常见的情况:
{5
6
9}
# [1] 9