如何在闪亮的文本和表中显示

时间:2017-01-04 14:53:10

标签: r shiny

如何显示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)

1 个答案:

答案 0 :(得分:2)

对于Table,我猜您没有提供存储/显示文本的变量,而Textpaste会覆盖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)