首页 > 代码库 > 美化RStudio的帮助页面

美化RStudio的帮助页面

R中的package及其函数实在太多,经常遇到不会使用或者忘记如何使用的的package和函数,所以总会查阅帮助文档,在Rstudio中提供了专门的help面板,当遇到不懂的package或者函数时只需在其前面加?或者将其用help()包裹,即可跳转到帮助页面。下面就是Rstudio的帮助页面:

 技术分享

可以看出,其界面毫无美感可言,可能是开发者想要使用者专注于学习如何使用而特意为之!学过HTML的都知道,可以用css修改页面的样式,让其变得跟家美观。原始文档也有css文件,在rstudio安装路径下的resources文件夹中的R.css文件就控制了页面的样式:

 技术分享

我们可以修改该文档让其变得更加美观!原R.css文档源码如下:

/* * R.css * * Copyright (C) 2009-16 by RStudio, Inc. * * Unless you have received this program directly from RStudio pursuant * to the terms of a commercial license agreement with RStudio, then * this program is licensed to you under the terms of version 3 of the * GNU Affero General Public License. This program is distributed WITHOUT * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT, * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the * AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details. * */body, td {   font-family: sans-serif;   font-size: 10pt;}::selection {   background: rgb(181, 213, 255);}::-moz-selection{   background: rgb(181, 213, 255);}a:visited {   color: rgb(50%, 0%, 50%);}h1 {   font-size: x-large;}h2 {   font-size: x-large;   font-weight: normal;}h3 {   color: rgb(35%, 35%, 35%);}h4 {   color: rgb(35%, 35%, 35%);   font-style: italic;}h5 {   color: rgb(35%, 35%, 35%);}h6 {   color: rgb(35%, 35%, 35%);   font-style: italic;}img.toplogo {   max-width: 4em;   vertical-align: middle;}img.arrow {   width: 30px;   height: 30px;   border: 0;}span.acronym {   font-size: small;}span.env {   font-family: monospace;}span.file {   font-family: monospace;}span.option {   font-family: monospace;}span.pkg {   font-weight: bold;}span.samp {   font-family: monospace;}div.vignettes a:hover {   background: rgb(85%, 85%, 85%);}table p {   margin-top: 0;   margin-bottom: 6px;}table[summary="R argblock"] tr td:first-child {   min-width: 24px;   padding-right: 12px;}

修改后的文档源码如下:

/* * R.css * * Copyright (C) 2009-11 by RStudio, Inc. * * Unless you have received this program directly from RStudio pursuant * to the terms of a commercial license agreement with RStudio, then * this program is licensed to you under the terms of version 3 of the * GNU Affero General Public License. This program is distributed WITHOUT * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT, * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the * AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details. * */body, td {   font-family: sans-serif;   font-size: 10pt;}::selection {   background: rgb(181, 213, 255);}::-moz-selection{   background: rgb(181, 213, 255);}a:visited {   color: rgb(50%, 0%, 50%);}h1 {   font-size: x-large;}h2 {   font-size: x-large;   font-weight: normal;}h3 {   color: rgb(35%, 35%, 35%);}h4 {   color: rgb(35%, 35%, 35%);   font-style: italic;}h5 {   color: rgb(35%, 35%, 35%);}h6 {   color: rgb(35%, 35%, 35%);   font-style: italic;}img.toplogo {   vertical-align: middle;}img.arrow {   width: 30px;   height: 30px;   border: 0;}span.acronym {   font-size: small;}span.env {   font-family: monospace;}span.file {   font-family: monospace;}span.option {   font-family: monospace;}span.pkg {   font-weight: bold;}span.samp {   font-family: monospace;}div.vignettes a:hover {   background: rgb(85%, 85%, 85%);}table p {   margin-top: 0;   margin-bottom: 6px;}/* Below is my customization to the help page appearance */body{  background-color: #fcfcfc;}body, td{    font-size: 15px !important;    font-family: "Segoe UI" !important;}pre, code, table tr td:nth-child(1){    font-family: "Consolas" !important;}code{  border: 1px solid #E1E1E8;  border-radius: 3px;  color: #D14;  background-color: #F7F7F9;  padding: 0px 4px;}a{  text-decoration: none;  color: #008AC6;}a:hover, a:focus{  color: #005580;  text-decoration: underline;}pre{    padding: 8px;    border-style: solid;    border-width: 1px 1px 1px 6px;    border-color: #EAEAEA;    border-left-color:  #418AB5;    background-color: #FAFAFA;    /* color: #005580; */}body>table:nth-child(1){  border: 1px solid #DDE4E6;  border-radius: 4px;  background-color: #ECF0F1;  padding: 4px 8px; }div, body>table:nth-child(1) td{      font-size: 10pt !important;  text-shadow: 1px 1px 0px #FFF;}div{  color: #DDE4E6;}h2 {   font-weight: 600 !important;   margin-top: 0.2em;   padding-bottom: 10px;   border-bottom: 1px solid #DDE4E6;   color: #418AB5;}h3 {   font-weight: 600;   text-transform: uppercase;   margin-top: 1.5em;   margin-bottom: 0.6em;}h3 ~ p, h3 ~ table, h3+* table {    /* margin-left: 20px; */    padding-left: 20px;}h3 ~ pre{  margin-left: 20px;}h3 + *{    margin-top: 0px;}dt {    font-style: italic;}p {  line-height: 24px;}hr{  border-style: hidden;}table[summary$="block"] p {   margin-bottom: 16px;}table[summary$="block"] td:nth-child(1) {    padding-right: 16px;}table[summary$="block"] td:nth-child(1) code{    padding-right: 16px;    border: none;    background: none;    font-weight: bold;    color: black;}table[summary$="block"] tr {  vertical-align: top;}table[summary$="block"] td:nth-child(2){  margin: 0px;}h2 + table tr:nth-child(even), dl table tr:nth-child(even){  background-color: #EEE;}h2 + table, dl table{  border-spacing: 0px 2px;}h2 + table{  width: 100%;  padding-left: 20px;}

也可以直接下载文末的R.css文件覆盖原始文件,然后重启Rstudio即可!

修改后的效果:

 技术分享