我有下面的数据框:
df <- data.frame(result=floor(rnorm(1000, 100, 20)))
Run Code Online (Sandbox Code Playgroud)
创建此直方图:
require(scales)
df <- data.frame(result=floor(rnorm(1000, 100, 20)))
ggplot(df)+
geom_histogram(aes(result, fill = (result<=80 | result > 95)),
binwidth = 5, center = 2.5, color = "black") +
scale_fill_manual(values=c("darkblue", "lightblue"), guide = F) +
labs(y = "Frequency", x = "Result") + scale_y_continuous(labels = comma)+
theme_classic(base_size = 16)+annotate("label",x=130,y=90, label = "text" )
Run Code Online (Sandbox Code Playgroud)
我添加了一个标签,但我想知道是否还有其他形状(可能是彩色的)可以放置文本。理想情况下是一个箭头,但也有带有文本和下方箭头的标签。

假设我有一个闪亮的仪表板,默认情况下使用垂直滚动条,因为右侧有一个大图,但由于某种原因,即使该图没有作为整体显示,我也不希望它在那里。我也不想降低绘图高度。可以这样做吗?
## app.R ##
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(title = "Basic dashboard"),
dashboardSidebar(),
dashboardBody(
# Boxes need to be put in a row (or column)
fluidRow(
box(plotOutput("plot1", height = 850)),
box(
title = "Controls",
sliderInput("slider", "Number of observations:", 1, 100, 50)
)
)
)
)
server <- function(input, output) {
set.seed(122)
histdata <- rnorm(500)
output$plot1 <- renderPlot({
data <- histdata[seq_len(input$slider)]
hist(data)
})
}
shinyApp(ui, server)
Run Code Online (Sandbox Code Playgroud) 无论操作系统和屏幕分辨率如何,有没有办法在闪亮的仪表板中调整绘图和框的高度?例如,在下面的示例中,我想在将显示应用程序的任何屏幕中覆盖仪表板主体中屏幕高度的 80%?
library(shiny)
library(shinydashboard)
library(shinydashboardPlus)
library(plotly)
library(ggplot2)
shinyApp(
ui = dashboardPagePlus(
header = dashboardHeaderPlus(
enable_rightsidebar = TRUE,
rightSidebarIcon = "gears"
),
sidebar = dashboardSidebar(),
body = dashboardBody(
navbarPage("Navbar!",
tabPanel("Plot",
boxPlus(
plotlyOutput("plot1")
)
))
),
title = "Right Sidebar"
),
server = function(input, output) {
output$plot1 <- renderPlotly({
p <- qplot(Petal.Width, Sepal.Length, data = iris, color = Species)
p <- ggplotly(p)
hide_legend(p)
})
}
)
Run Code Online (Sandbox Code Playgroud) 我有下面闪亮的应用程序,我在其中使用shinycustomLoader和shinycssLoader创建加载消息。我想知道是否有一种方法可以在特定时间后添加多条消息。例如,第一条消息将是"Analyzing",加载 15 秒后它将被替换为"Almost there"。如果有其他方法或包可以做到这一点,我很高兴知道。
library(shiny)
library(shinycssloaders)
library(shinycustomloader)
ui <- fluidPage(
actionButton("go", "Go"),
shinycssloaders::withSpinner(
plotOutput("plot")
),
withLoader(plotOutput("plot2"),type = "text",loader = "Text")
)
server <- function(input, output) {
output$plot <- renderPlot({
input$go
plot(runif(10000000))
})
output$plot2 <- renderPlot({
input$go
plot(runif(10000000))
})
}
shinyApp(ui, server)
Run Code Online (Sandbox Code Playgroud) 使用时有什么方法可以隐藏列名 DT::datatable()
现在返回所有数据:
empty<-data.frame(c("a","d","d"),c("s","d","d"))
library(DT)
datatable(empty,colnames = F)
Run Code Online (Sandbox Code Playgroud) 我有一个基本的闪亮应用程序,我希望能够在其中设置名为 Navnar 的导航栏菜单的高度!我没有看到任何设置其高度的选择。
#ui.r
library(markdown)
navbarPage("Navbar!",
tabPanel("Plot",
sidebarLayout(
sidebarPanel(
),
mainPanel(
)
)
),
tabPanel("Summary"
),
navbarMenu("More",
tabPanel("Table"
)
)
)
#server.r
function(input, output, session) {
}
Run Code Online (Sandbox Code Playgroud) 我想知道是否有一种方法可以通过闪亮的应用程序在同一个 Excel 文件中但在不同的工作表中下载 2 个数据帧。
library(shiny)
library(xlsx)
ui <- shinyUI(fluidPage(
titlePanel("Testing File upload"),
sidebarLayout(
sidebarPanel(
downloadButton("dl","Export in Excel")
),
mainPanel(
)
)
))
server <- shinyServer(function(input, output) {
output$dl <- downloadHandler(
filename = function() {
paste0("df_dmodel", "_Table", ".xls")
},
content = function(file){
tbl<-iris
tbl2<-mtcars
write.xlsx(tbl,tbl2 file,
sheetName = "Sheet1", row.names = FALSE)
}
)
})
shinyApp(ui = ui, server = server)
Run Code Online (Sandbox Code Playgroud) 我有3个数据帧
Drug<-c("ab","bc","cd","ef","gh")
Target<-c("qwewr","saff","cxzcc","sadda","sadd")
fileA<-data.frame(Drug,Target)
Drug<-c("ab","bc","cdD","efc","ghg","hj")
Target<-c("qwewr","saff","cxzccf","saddav","sadd","bn")
fileB<-data.frame(Drug,Target)
Drug<-c("abB","bcv","cdD","efc")
Target<-c("qwewrm","saff","cxzccfh","saddav")
fileC<-data.frame(Drug,Target)
Run Code Online (Sandbox Code Playgroud)
正如你所看到的,每一个都包含一对"药物" - "目标".每个数据帧仅包含唯一对.但是您可以在其他数据帧中找到完全相同的对.我想实现的是创建一个新的数据帧,将提取的第一列中的所有唯一对,然后在其他3列将有fileA, fileB和fileC这将充满1如果对存在,0如果对不存在.就像是:
Pairs fileA fileB fileC
1: abqwewr 1 1 1
2: bcsaff 1 1 1
3: cdcxzcc 1 1 1
4: efsadda 1 1 1
5: ghsadd 1 1 0
6: cdDcxzccf 0 0 0
7: efcsaddav 0 0 0
8: ghgsadd 0 0 0
9: hjbn 0 0 0
10: abBqwewrm 0 0 0
11: bcvsaff 0 0 …Run Code Online (Sandbox Code Playgroud) 我有下面的数据框,我想通过将符号Sold_Pr替换为来将列转换为数字comma.
subs<-structure(list(Sold_Pr = c("6,500.00", "173,000.00", "60,000.00"
), Area = structure(c(1L, 1L, 1L), .Label = c("411", "415", "981",
"8001", "8002", "8003", "8004", "8005", "8006", "8007", "8008",
"8009", "8010", "8011", "8012", "8013", "8014", "8015", "8016",
"8017", "8018", "8019", "8020", "8021", "8022", "8023", "8024",
"8025", "8026", "8027", "8028", "8029", "8030", "8031", "8034",
"8035", "8037", "8038", "8039", "8040", "8041", "8042", "8043",
"8044", "8045", "8046", "8047", "8048", "8049", "8050", "8051",
"8052", "8053", "8055", "8056", "8057", "8058", "8059", "8060",
"8061", "8062", "8063", …Run Code Online (Sandbox Code Playgroud) 我有一个长矩阵,我想填写,rnorm(1)但它需要很长时间(不像下面的示例).是否有另一种方法,因为行数和列数总是相等但是动态的.
my <- matrix(c(0), nrow= 3, ncol = 3)
for (i in 1:3){
for (j in 1:3){
my[i,j]<-rnorm(1)
}
}
Run Code Online (Sandbox Code Playgroud)