大神一句話,菜鳥跑半年。我不是大神,但我可以縮短你走彎路的半年~
就像歌兒唱的那樣,如果你不知道該往哪兒走,就留在這學(xué)點(diǎn)生信好不好~
這里有豆豆和花花的學(xué)習(xí)歷程,從新手到進(jìn)階,生信路上有你有我!
從前只知道shiny和shinydashboard,開發(fā)簡單的網(wǎng)頁是夠的,但一旦對顏值有了要求,就不能對html和css絲毫不知。顏值與技術(shù)齊飛啦啦啦。
關(guān)于shiny與CSS:https://shiny./articles/css.html
這幾天搜索發(fā)現(xiàn)了幾個(gè)UI包,學(xué)會了基本操作,來分享一下。
1.shinythemes
shiny主題,最兼容原始shiny的美化包,內(nèi)置http:///上幾乎所有的bootstrap主題,手到擒來。是這樣的:

鏈接:https://rstudio./shinythemes/
shinytheme有一個(gè)很好的功能:themeselector,可以在線切換主題,方便選擇和比較。
if(!require(shinythemes)) install.packages('shinythemes')
shinyApp(
ui = fluidPage(
shinythemes::themeSelector(), # <>
sidebarPanel(
textInput('txt', 'Text input:', 'text here'),
sliderInput('slider', 'Slider input:', 1, 100, 30),
actionButton('action', 'Button'),
actionButton('action2', 'Button2', class = 'btn-success'),
selectInput('txt1','species', c('a','b','c'))
),
mainPanel(
tabsetPanel(
tabPanel('Tab 1'),
tabPanel('Tab 2')
)
)
),
server = function(input, output) {}
)
2.dashboardthemes
如果網(wǎng)頁是用shinydashboard寫的,shiny主題很多用不了。這事就有了dashboardthemes:
可供選擇的只有七個(gè)主題。但擴(kuò)展性非常強(qiáng),可以自己寫主題,每一個(gè)控件都是可改動的,非常實(shí)用。

鏈接:https://rstudio./shinythemes/
3.semantic.dashboard
https://github.com/Appsilon/semantic.dashboard
https:///create-outstanding-dashboards-with-the-new-semantic-dashboard-package/
這是一個(gè)公司開發(fā)的dashboard包美化版本,示例造型是這樣的:

可選的theme有不少:http:///themes/
參考鏈接:https://github.com/Appsilon/semantic.dashboard
https:///create-outstanding-dashboards-with-the-new-semantic-dashboard-package/
library(shiny)
library(semantic.dashboard)
ui <>
dashboardHeader(),
dashboardSidebar(),
dashboardBody()
)
server <>function(input, output, session) {
})
shinyApp(ui, server)
示例的完整代碼:
library(shiny)
library(semantic.dashboard)
library(ggplot2)
library(plotly)
library(DT)
ui <>
dashboardHeader(color = 'blue',title = 'Dashboard Demo', inverted = TRUE),
dashboardSidebar(
size = 'thin', color = 'teal',
sidebarMenu(
menuItem(tabName = 'main', 'Main', icon = icon('car')),
menuItem(tabName = 'extra', 'Extra', icon = icon('table'))
)
),
dashboardBody(
tabItems(
selected = 1,
tabItem(
tabName = 'main',
fluidRow(
box(width = 8,
title = 'Graph 1',
color = 'green', ribbon = TRUE, title_side = 'top right',
column(width = 8,
plotOutput('boxplot1')
)
),
box(width = 8,
title = 'Graph 2',
color = 'red', ribbon = TRUE, title_side = 'top right',
column(width = 8,
plotlyOutput('dotplot1')
)
)
)
),
tabItem(
tabName = 'extra',
fluidRow(
dataTableOutput('carstable')
)
)
)
), theme = 'cerulean'
)
server <>function(input, output, session) {
data('mtcars')
colscale <>[['red']], semantic_palette[['green']], semantic_palette[['blue']])
mtcars$am <>0,1),
labels=c('Automatic','Manual'))
output$boxplot1 <>
ggplot(mtcars, aes(x = am, y = mpg)) +
geom_boxplot(fill = semantic_palette[['green']]) +
xlab('gearbox') + ylab('Miles per gallon')
})
output$dotplot1 <>
ggplotly(ggplot(mtcars, aes(wt, mpg))
+ geom_point(aes(colour=factor(cyl), size = qsec))
+ scale_colour_manual(values = colscale)
)
})
output$carstable <>
})
shinyApp(ui, server)
4.bs4Dash
這個(gè)包可以作為shiny的輔助,是18年剛開發(fā)的,目前基本沒有中文教程,看下他的結(jié)構(gòu):
cran頁面:https://cran./web/packages/bs4Dash/index.html
github:https://github.com/RinteRface/bs4Dash
(1)空框架
if(!require(bs4Dash))install.packages('bs4Dash')
library(shiny)
library(bs4Dash)
shiny::shinyApp(
ui = bs4DashPage(
navbar = bs4DashNavbar(),
sidebar = bs4DashSidebar(),
controlbar = bs4DashControlbar(),
footer = bs4DashFooter(),
title = 'Basic Dashboard',
body = bs4DashBody()
),
server = function(input, output) {}
)
(2)示例網(wǎng)頁,除了前面的加載,其實(shí)只有一行代碼看示例
if(!require(fontawesome))devtools::install_github('rstudio/fontawesome')
if(!require(shinyWidgets))install.packages('shinyWidgets')
if(!require(bs4Dash))install.packages('bs4Dash')
if(!require(plotly))install.packages('plotly')
library(shiny)
library(fontawesome)
library(shinyWidgets)
library(bs4Dash)
library(plotly)
bs4DashGallery()
