亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在 R Shiny 中創建 HTML 表格

在 R Shiny 中創建 HTML 表格

海綿寶寶撒 2024-01-03 15:21:47
下面是在記事本中創建的表格(使用 HTML)。我需要使用標簽功能在 R閃亮中復制相同的內容。我知道我們可以在沒有 R閃亮標簽的情況下填充這個表。但我可以知道如何使用 R閃亮中的html標簽創建這個表嗎?我的意思是像下面的示例一樣。HTML 和 CSS 專家有人可以幫助我嗎?樣本tags$table(tags$thead("Head", tags$tr.........)))
查看完整描述

1 回答

?
慕婉清6462132

TA貢獻1804條經驗 獲得超2個贊

由于您沒有提供制作該表的 HTML 代碼,我自己復制了它:


<table border = "5">

  <thead>

    <tr>

      <th colspan="2" height = "100" width = "800">TABLE TITLE</th>

    </tr>

  </thead>

  <tbody>

    <tr>

        <style>

        tr:nth-child(1) { border: solid thick; }

        </style>

      <td align = "center"><strong>Column A</strong></td>

      <td align = "center"><strong>Column B</strong></td>

    </tr>

    <tr style="border: solid thick">

      <td align = "center"><strong>Data 1</strong></td>

      <td align = "center"><strong>Data 2</strong></td>

  </tbody>

</table>

現在,您幾乎可以按照 HTML 流程直接將其轉換為 R 代碼,忽略將放置在一個函數調用中的樣式標簽。


  tags$head(tags$table(border = 5, 

                       tags$thead(

                         tags$tr(

                           tags$th(colspan = 2, height = 100, width = 800, 

                                   align = "center", "TABLE TITLE")

                           )

                       ), 

                       tags$tbody(

                         tags$tr(

                           tags$td(align = "center", strong("Column A")),

                           tags$td(align = "center", strong("Column B"))

                         ),

                         tags$tr(

                           tags$td(align = "center", "Data 1"),

                           tags$td(align = "center", "Data 2")

                         )

                       )

  )

  )

其中<對應于(且同樣</對應于)。如果在前一個標簽關閉之前打開一個新標簽,即在 open 中<放置一個新標簽。無論如何,最終的輸出只是 HTML 代碼,因此請繼續嘗試,直到輸出與您擁有的 HTML 匹配為止。tags$...tags$...


然而,需要相當多的 CSS 才能進入決賽桌,因為它有額外的樣式。我們使用一次tags$head(tags$style())調用將所有 CSS 代碼放在一個位置以提高可讀性。


  tags$head(tags$style(


  'thead {

    display: table-header-group;

    vertical-align: middle;

    border-color: inherit;

  }


    tr:nth-child(1) {

      border: solid thick;

    }


    tr:nth-child(2) {

      border: solid thick;

    }


    th {

      text-align: center

      ;

      }


   td, th {

    outline: none;

   }


    table { 

      display: table;

      border-collapse: separate;

      white-space: normal;

      line-height: normal;

      font-family: times-new-roman;

      font-weight: normal;

      font-size: medium;

      font-style: normal;

      color: -internal-quirk-inherit;

      text-align: start;

      border-spacing: 2px;

      border-color: grey;

      font-variant: normal;

    }  


    td {

      display: table-cell;

      vertical-align: inherit;

    }


    tr {

      display: table-row;

      vertical-align: inherit;

    }





  '


  ))

如果您有嘗試復制的源代碼,則可以在瀏覽器中使用檢查元素來獲取 CSS 代碼。如果沒有,您將需要一些外部資源(例如 Stackoverflow、WS3 學校、JSfiddle 等)來獲得最終的 Web 應用程序。


將所有內容整合到一個閃亮的應用程序中:


library(shiny)


ui <- fluidPage(


  tags$head(tags$style(


  'thead {

    display: table-header-group;

    vertical-align: middle;

    border-color: inherit;

  }


    tr:nth-child(1) {

      border: solid thick;

    }


    tr:nth-child(2) {

      border: solid thick;

    }


    th {

      text-align: center

      ;

      }


   td, th {

    outline: none;

   }


    table { 

      display: table;

      border-collapse: separate;

      white-space: normal;

      line-height: normal;

      font-family: times-new-roman;

      font-weight: normal;

      font-size: medium;

      font-style: normal;

      color: -internal-quirk-inherit;

      text-align: start;

      border-spacing: 2px;

      border-color: grey;

      font-variant: normal;

    }  


    td {

      display: table-cell;

      vertical-align: inherit;

    }


    tr {

      display: table-row;

      vertical-align: inherit;

    }





  '


  )),


  tags$head(tags$table(border = 5, 

                       tags$thead(

                         tags$tr(

                           tags$th(colspan = 2, height = 100, width = 800, 

                                   align = "center", "TABLE TITLE")

                           )

                       ), 

                       tags$tbody(

                         tags$tr(

                           tags$td(align = "center", strong("Column A")),

                           tags$td(align = "center", strong("Column B"))

                         ),

                         tags$tr(

                           tags$td(align = "center", "Data 1"),

                           tags$td(align = "center", "Data 2")

                         )

                       )

  )

  )

)



server <- function(input, output, session) {


}


shinyApp(ui, server)

這使:

https://img1.sycdn.imooc.com/65950b330001bc1d08900210.jpg

查看完整回答
反對 回復 2024-01-03
  • 1 回答
  • 0 關注
  • 153 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號