视觉增强

案例研究:使用 R 的 Shiny 构建 Web 应用

Dean Attali

Shiny Consultant

Shiny 表格

tableOutput("table")

output$table <- renderTable({ gapminder })

chapter3_4_visual_enhancements.003.png

案例研究:使用 R 的 Shiny 构建 Web 应用

用 DT 做更好的表格

DT::dataTableOutput("table")

output$table <- DT::renderDataTable({ gapminder })

chapter3_4_visual_enhancements.004.png

案例研究:使用 R 的 Shiny 构建 Web 应用

用 DT 做更好的表格

DT::dataTableOutput("table")

output$table <- DT::renderDataTable({ gapminder })

chapter3_4_visual_enhancements.005.png

案例研究:使用 R 的 Shiny 构建 Web 应用

用 DT 做更好的表格

DT::dataTableOutput("table")

output$table <- DT::renderDataTable({ gapminder })

chapter3_4_visual_enhancements.006.png

案例研究:使用 R 的 Shiny 构建 Web 应用

用 DT 做更好的表格

DT::dataTableOutput("table")

output$table <- DT::renderDataTable({ gapminder })

chapter3_4_visual_enhancements.007.png

案例研究:使用 R 的 Shiny 构建 Web 应用

用 DT 做更好的表格

DT::dataTableOutput("table")

output$table <- DT::renderDataTable({ gapminder })

chapter3_4_visual_enhancements.008.png

案例研究:使用 R 的 Shiny 构建 Web 应用

将 UI 拆分为选项卡

chapter3_4_visual_enhancements.009.png

案例研究:使用 R 的 Shiny 构建 Web 应用

将 UI 拆分为选项卡

chapter3_4_visual_enhancements.010.png

案例研究:使用 R 的 Shiny 构建 Web 应用

将 UI 拆分为选项卡

tabPanel(title = "tab 1", "content goes here")

tabPanel(title = "tab 2", "second tab", plotOutput("plot"))
fluidPage(

tabsetPanel(
tabPanel(title = "tab 1", "first tab content goes here"), tabPanel(title = "tab 2", "second tab", plotOutput("plot")), tabPanel(title = "tab 3", textInput("text", "Name", ""))
)
)

chapter3_4_visual_enhancements.016.png

案例研究:使用 R 的 Shiny 构建 Web 应用

CSS:微调应用外观

  • 层叠样式表(Cascading Style Sheets)
  • 用于自定义网页任意元素外观的标记语言
    • Shiny 的 UI 是网页
  • 背景色、文字颜色、字号、留白、字体等
案例研究:使用 R 的 Shiny 构建 Web 应用

CSS 语法

  • CSS 规则语法

    #ID {
      property: value;
      property: value;
      ...
    }
    
  • ID 为要应用样式的元素 ID

  • 在 Shiny 中添加 CSS:使用 tags$style()

    ui <- fluidPage(
      tags$style("
        #ID {
          property: value;
        }
      ")
    )
    
案例研究:使用 R 的 Shiny 构建 Web 应用

CSS 示例

ui <- fluidPage(
  textInput("name", "Enter your name", "Dean"),
  tableOutput("table")
)

chapter3_4_visual_enhancements.029.png

案例研究:使用 R 的 Shiny 构建 Web 应用

CSS 示例

ui <- fluidPage(
  textInput("name", "Enter your name", "Dean"),
  tableOutput("table")
)

chapter3_4_visual_enhancements.030.png

案例研究:使用 R 的 Shiny 构建 Web 应用

CSS 示例

ui <- fluidPage(
  textInput("name", "Enter your name", "Dean"),
  tableOutput("table")
)

chapter3_4_visual_enhancements.031.png

案例研究:使用 R 的 Shiny 构建 Web 应用

CSS 示例

ui <- fluidPage(
  textInput("name", "Enter your name", "Dean"),
  tableOutput("table")
)

chapter3_4_visual_enhancements.032.png

案例研究:使用 R 的 Shiny 构建 Web 应用

CSS 示例

css <- "

#name { color: red; }
#table { background: yellow; font-size: 24px; }
"
ui <- fluidPage(

tags$style(css),
textInput("name", "Enter your name", "Dean"), tableOutput("table") )
案例研究:使用 R 的 Shiny 构建 Web 应用

Passons à la pratique !

案例研究:使用 R 的 Shiny 构建 Web 应用

Preparing Video For Download...