如何显示h3("数字结果")和h3("摘要声明")?谢谢。
这是我的ui.R和server.R。
以下是我的ui.R文件的代码:
library(shiny)
ui <- shinyUI(fluidPage(
titlePanel("aaaaaaaaaaaaaaaa"),
tabsetPanel(
navbarMenu("Means",
tabPanel("One Mean"),
tabPanel("Two Means",
wellPanel(
checkboxInput(inputId = "s1", label = "S1" , value = FALSE),
checkboxInput(inputId = "s2", label = "S2", value = FALSE)
),
sidebarPanel(
p(strong("Error Rates")),
numericInput("alpha", label="Alpha", min=0, max=1,value=0.05),
numericInput("power", "Power", 0.8),
actionButton("submit","Submit")
),
mainPanel(
tabsetPanel(
tabPanel("Main",
tableOutput("Table"),
verbatimTextOutput("Text")
)
)
)
)
))))
以下是我的server.R文件的代码:
server <- shinyServer(function(input, output) {
output$Table <- renderTable({
if(input$submit > 0) {
h3("Numeric Results")
output<-data.frame(input$alpha,input$power)
output
}
})
output$Text<-renderPrint({
if(input$submit > 0) {
h3("Summary Statements")
paste("alpha and power are",input$alpha,"and",input$power)
}
})
})
shinyApp(ui = ui, server = server)
答案 0 :(得分:2)
对于Table
,我猜您没有提供存储/显示文本的变量,而Text
,paste
会覆盖h3
代码。如果您对paste
代码发表评论,则可以看到h3
代码。要拥有多行文本,您可以尝试类似下面的代码。
library(shiny)
ui <- shinyUI(fluidPage(
titlePanel("aaaaaaaaaaaaaaaa"),
tabsetPanel(
navbarMenu("Means",
tabPanel("One Mean"),
tabPanel("Two Means",
wellPanel(
checkboxInput(inputId = "s1", label = "S1" , value = FALSE),
checkboxInput(inputId = "s2", label = "S2", value = FALSE)
),
sidebarPanel(
p(strong("Error Rates")),
numericInput("alpha", label="Alpha", min=0, max=1,value=0.05),
numericInput("power", "Power", 0.8),
actionButton("submit","Submit")
),
mainPanel(
tabsetPanel(
tabPanel("Main",
htmlOutput("header"),
tableOutput("Table"),
htmlOutput("Text")
)
)
)
)
))))
server <- shinyServer(function(input, output) {
output$header <- renderText({
if(input$submit > 0) {
HTML(paste0("<h3>","Numeric Results","</h3>"))
}
})
output$Table <- renderTable({
if(input$submit > 0) {
output<-data.frame(input$alpha,input$power)
output
}
})
output$Text<-renderPrint({
if(input$submit > 0) {
str1 <- (paste0("<h3>", "Summary Statements", "</h3>"))
str2 <- paste("alpha and power are",input$alpha,"and",input$power)
HTML(paste(str1, str2, sep = '<br/>'))
}
})
})
shinyApp(ui = ui, server = server)