使用CSS美化shiny app效果

shiny 是R语言的web框架,当我们要开发一个shiny app时,一般包含两个文件,ui.R和server.R。

本文介绍一个使用CSS对shiny app效果进行美化的简单例子。该例子是在shiny examples中的01_hello基础上修改而成。

先看ui.R程序

library(shiny)
# Define UI for application that draws a histogram
fluidPage(

 #使用includeCSS函数加载CSS
  includeCSS("style.css"),
  # Application title
  headerPanel("Hello World"),

  # Sidebar with a slider input for the number of bins
  sidebarLayout(
    sidebarPanel(
      sliderInput("bins",
                  "Number of bins:",
                  min = 1,
                  max = 50,
                  value = 30)
    ),

    # Show a plot of the generated distribution
    mainPanel(
      plotOutput("distPlot")
    )
  )
)

然后是server.R程序

library(shiny)


# Define server logic required to draw a histogram
function(input, output) {


  # Expression that generates a histogram. The expression is
  # wrapped in a call to renderPlot to indicate that:
  #
  #  1) It is "reactive" and therefore should be automatically
  #     re-executed when inputs change
  #  2) Its output type is a plot
  


  output$distPlot <- renderPlot({
    x    <- faithful[, 2]  # Old Faithful Geyser data
    bins <- seq(min(x), max(x), length.out = input$bins + 1)


    # draw the histogram with the specified number of bins
    hist(x, breaks = bins, col = 'darkgray', border = 'white')
  })


}

我们设置的CSS其实也很简单,就是把标题的字体颜色以及北京颜色设置了一下。style.css具体代码如下:

@import url("//fonts.googleapis.com/css?family=Lobster|Cabin:400,700");

h1 {
  font-family: 'Lobster', cursive;
  font-weight: 500;
  line-height: 1.1;
  color: #ad1d28;
}


body {
  background-color: #4F94CD;
}

效果图如下图所示:


如有任何问题请跟我联系,点击链接加入群【R语言&大数据分析】:https://jq.qq.com/?_wv=1027&k=4CSCAUx。或者加群号456726635。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值