【问题标题】:How to show text and table in shiny如何以闪亮的方式显示文本和表格
【发布时间】:2017-01-04 23:31:22
【问题描述】:

如何显示 h3("Numeric Results") 和 h3("Summary Statements")?谢谢。

这是我的 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)

【问题讨论】:

    标签: r shiny


    【解决方案1】:

    对于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)
    

    【讨论】:

      猜你喜欢
      • 2016-08-11
      • 2015-06-06
      • 2019-03-28
      • 1970-01-01
      • 2013-10-28
      • 2018-06-02
      • 2020-08-04
      • 2017-08-08
      • 2017-05-19
      相关资源
      最近更新 更多