1. 程式人生 > >R語言包翻譯——翻譯

R語言包翻譯——翻譯

you ges sam 運行 badge like level bar center

Shiny-cheatsheet

作者:賈慧 作品來源:百度百科

.炫酷外觀

皮膚skins

儀表盤包括很多的主題或者皮膚。默認的為blue藍色,此外,還有其他的顏色,包括:black黑色,purple紫色,green綠色,red紅色,yellow黃色等。可以使用dashboardPage(skin = "blue"), dashboardPage(skin = "black")

等進行設置。

ui <- dashboardPage(skin = "black",

dashboardHeader(title = "Value boxes"),

dashboardSidebar(),

dashboardBody()

)

註銷面板logout panel

(這需要shinydashboard 0.5.1或更高版本顯示。)shinydashboard應用運行shiny服務器之前,需要經過身份驗證的用戶才能登錄,面板在右上角顯示用戶名和註銷鏈接。

註銷面板與shinydashboard更很好地集成。正如你所看到的在上面的截圖中,默認註銷面板部分掩蓋了下拉菜單圖標。我們可以添加一個用戶面板與動態

UI(在服務器上生成)和隱藏默認註銷面板,如下所示:

程序:

library(shiny)

library(shinydashboard)

library(httr)

library(jsonlite)

library(data.table)

library(dplyr)

library(rvest)

library(magrittr)

ui <- dashboardPage(

dashboardHeader(

title = "SSP logout",

dropdownMenu(type = "messages", badgeStatus = "success",

messageItem("Message 1", "Content of a message.")

)

),

dashboardSidebar(

# Custom CSS to hide the default logout panel

tags$head(tags$style(HTML(‘.shiny-server-account { display: none; }‘))),

# The dynamically-generated user panel

uiOutput("userpanel"),

sidebarMenu(

menuItem("Menu item 1", icon = shiny::icon("calendar"))

)

),

dashboardBody()

)

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

# Generate the dynamic UI for the logout panel

output$userpanel <- renderUI({

# session$user is non-NULL only in authenticated sessions

if (!is.null(session$user)) {

sidebarUserPanel(

span("Logged in as ", session$user),

subtitle = a(icon("sign-out"), "Logout", href="__logout__"))

}

})

}

shinyApp(ui, server)

其他程序:

library(shiny)

library(shinydashboard)

library(httr)

library(jsonlite)

library(data.table)

library(dplyr)

library(rvest)

library(magrittr)

header <- dashboardHeader(title="CYBER Dashboard")

sidebar <- dashboardSidebar()

body <- dashboardBody(

fluidPage(

fluidRow(

a(href="http://isc.sans.org/",

target="_blank", uiOutput("infocon")),

a(href="http://www.symantec.com/security_response/threatcon/",

target="_blank", uiOutput("threatcon")),

a(href="http://webapp.iss.net/gtoc/",

target="_blank", uiOutput("alertcon"))

)

)

)

ui <- dashboardPage(header, sidebar, body, skin="black")

server <- function(input, output) {

output$infocon <- renderUI({

infocon_url <- "https://isc.sans.edu/api/infocon?json"

infocon <- fromJSON(content(GET(infocon_url)))

valueBox(

value="Yellow",

subtitle="SANS Infocon",

icon=icon("bullseye"),

color=ifelse(infocon$status=="test", "blue", infocon$status)

)

})

output$threatcon <- renderUI({

pg <- html("http://www.symantec.com/security_response/#")

pg %>%

html_nodes("div.colContentThreatCon > a") %>%

html_text() %>%

extract(1) -> threatcon_text

tcon_map <- c("green", "yellow", "orange", "red")

names(tcon_map) <- c("Level 1", "Level 2", "Level 3", "Level 4")

threatcon_color <- unname(tcon_map[gsub(":.*$", "", threatcon_text)])

threatcon_text <- gsub("^.*:", "", threatcon_text)

valueBox(

value=threatcon_text,

subtitle="Symantec ThreatCon",

icon=icon("tachometer"),

color=threatcon_color

)

})

output$alertcon <- renderUI({

pg <- html("http://xforce.iss.net/")

pg %>%

html_nodes(xpath="//td[@class=‘newsevents‘]/p") %>%

html_text() %>%

gsub(" -.*$", "", .) -> alertcon_text

acon_map <- c("green", "blue", "yellow", "red")

names(acon_map) <- c("AlertCon 1", "AlertCon 2", "AlertCon 3", "AlertCon 4")

alertcon_color <- unname(acon_map[alertcon_text])

valueBox(

value=alertcon_text,

subtitle="IBM X-Force",

icon=icon("warning"),

color=alertcon_color

)

})

}

shinyApp(ui, server)

CSS

You can add custom CSS to your app by creating a www/ subdirectory to your app and adding a CSS file there. Suppose, for example, you want to change the title font of your dashboard to the same font as the rest of the dashboard, so that it looks like this:

To do this, first create a file named www/custom.css with the following:

.main-header .logo {

font-family: "Georgia", Times, "Times New Roman", serif;

font-weight: bold;

font-size: 24px;

}

Then refer to that CSS file from the UI of your app:

## ui.R ##

dashboardPage(

dashboardHeader(title = "Custom font"),

dashboardSidebar(),

dashboardBody(

tags$head(

tags$link(rel = "stylesheet", type = "text/css", href = "custom.css")

)

)

)

A second way to include CSS is to put it directly in the UI code for your app:

## ui.R ##

dashboardPage(

dashboardHeader(title = "Custom font"),

dashboardSidebar(),

dashboardBody(

tags$head(tags$style(HTML(‘ .main-header .logo {

font-family: "Georgia", Times, "Times New Roman", serif;

font-weight: bold;

font-size: 24px;

}

‘))) )

)

4.4長標題

In some cases, the title that you wish to use won’t fit in the default width in the header bar. You can make the space for the title wider with the titleWidth option. In this example, we’ve increased the width for the title to 450 pixels, and also set the background color of the title area (using custom CSS) to be the same as the rest of the header bar.

shinyApp(

ui = dashboardPage(

dashboardHeader(

title = "Example of a long title that needs more space",

titleWidth = 450

),

dashboardSidebar(),

dashboardBody(

# Also add some custom CSS to make the title background area the same

# color as the rest of the header.

tags$head(tags$style(HTML(‘ .skin-blue .main-header .logo {

}

.skin-blue .main-header .logo:hover {

background-color: #3c8dbc;

}

‘))) )

),

server = function(input, output) { }

)

側邊欄寬度sidebar width

To change the width of the sidebar, you can use the width option. This example has a wider title and sidebar:

shinyApp(

ui = dashboardPage(

dashboardHeader(

title = "Title and sidebar 350 pixels wide",

titleWidth = 350

),

dashboardSidebar(

width = 350,

sidebarMenu(

menuItem("Menu Item")

)

),

dashboardBody()

),

server = function(input, output) { }

)

R語言包翻譯——翻譯