suffixes
在merge
仅公共列名的作品.无论如何还要将其扩展到其余列,而无需在合并之前手动更新列?
那是 -
df1 <- data.table(
a = c(1,2,3,4,5,6),
b = c('a','b','f','e','r','h'),
d = c('q','l','o','n','q','z')
)
df2 <- data.table(
a = c(1,2,3,4,5,6),
d = c('q','l','o','n','q','z')
)
colnames(merge(df1,df2, by = 'a', suffixes = c("1","2")))
#[1] "a" "b" "d1" "d2" what it does
#[1] "a" "b1" "d1" "d2" what I'd like it to do
Run Code Online (Sandbox Code Playgroud)
我正在处理的这种方式类似于@ mrip的答案.
df1 <- data.table(
a = c(1,2,3,4,5,6),
b = c('a','b','f','e','r','h'),
r = c('a','b','f','e','r','h'),
d = c('q','l','o','n','q','z')
)
df2 <- data.table(
a = c(1,2,3,4,5,6),
c …
Run Code Online (Sandbox Code Playgroud) 使用时shinydashboard
我发现有些图标似乎有效,而有些则没有.在下面的示例中,当clock-o图标正常工作时,电池已满的图标不起作用.我无法弄清楚为什么会发生这种情况.
library(shiny)
library(shinydashboard)
header <- dashboardHeader(title="Some Icons Not Working?")
# No sidebar --------------------------------------------------------------
sm <- sidebarMenu(
sm <- sidebarMenu(
menuItem(
text="asdf",
tabName="asdfasdf",
icon=icon("battery-full")),
menuItem(
text="qwer",
tabName="qwerqwer",
icon=icon("clock-o"))
)
)
sidebar <- dashboardSidebar(sm)
# Compose dashboard body --------------------------------------------------
body <- dashboardBody(
tabItems(
)
)
# Setup Shiny app UI components -------------------------------------------
ui <- dashboardPage(header, sidebar, body, skin="black")
# Setup Shiny app back-end components -------------------------------------
server <- function(input, output) {
}
# Render Shiny app --------------------------------------------------------
shinyApp(ui, server)
Run Code Online (Sandbox Code Playgroud) 我正在开发一个R包,需要使用snowfall
包装提供的并行化.snowfall
似乎没有导入同为其他包一样ggplot2
,data.table
等我已经包括snowfall
,rlecuyer
以及snow
在描述文件,命名空间的文件,并在函数本身的进口参数.当我尝试访问此功能时,我收到以下错误:
Error in sfInit() : could not find function "setDefaultClusterOptions"
该sfInit
函数似乎有一个nostart
/ nostop
参数,它表示与嵌套用法有关,sfInit
但这对我来说似乎也没有.
实际的代码本身使用一个sfInit
(我得到错误的地方),一些sfExport
s和sfLibrary
s,以及一个sfLapply
.
可能的解决方案:如果我snow
从导入部分移动到Desciption文件中的depends部分,它似乎有效.我不知道为什么.
我需要读取具有不同压缩格式的多个压缩文件.我不希望手动解压缩所有文件.我希望R能够独立于压缩格式处理解压缩和读取.这就是我被困住的地方.
我可以用zip - unzip,gz - gzfile等构造一个具有switch case结构的函数,但我想知道是否已经有一些函数可以解压缩文件而不管压缩格式如何.
任何建议表示赞赏.非常感谢!
PS:我知道read.table
可以读取(一些,如果不是全部)压缩文件.但是,我一直在努力data.table::fread
(因为它更快),而且似乎无法读取压缩文件(http://r.789695.n4.nabble.com/fread-on-gzipped-files- td4663116.html - 但是?).我宁愿暂时解压缩和使用fread而不是使用read.table.
我试图创建一个使用图表facet_wrap
与facet_grid
内每个包裹面,但我不能.有什么建议?
例如,如果我按月平均2个数量进行年度比较,我希望 -
我能来的最近的是这个,
library(ggplot2)
# create dataset
df <- data.frame(
Facet1 = rep(c(1,2,3),24),
Facet2 = c(rep(1,24),rep(2,24)),
Year = rep(c(rep(2012,12),rep(2013,12)),2),
Month = rep(rep(1:12,2),2),
ValueX = sample(0:5,144,replace = TRUE),
ValueY = sample(0:5,144,replace = TRUE)
)
df <- df[!(df$Facet1 == 2 & df$Facet2 == 2),]
ggplot(df, aes(ValueX, ValueY)) + geom_point() +
facet_grid(Facet2 + Year ~ Month)
Run Code Online (Sandbox Code Playgroud)
虽然,我理想的是,这是符合这一点的(在我看来,类似于ggplot() ... + facet_grid(Year ~ Month) + facet_wrap(Facet2~.)
) -
PS:我认为后者的各个方面更容易区分和更整洁.评论?任何替代品?
题
我有两个下拉菜单,dd2中可用的选择取决于dd1中选择的选项。我无法弄清楚如何更改下拉菜单2的选项,但保留已进行的选择。我还应该能够通过下拉菜单2删除先前选择的项目。
例
假设dd1是国家/地区:印度,英国,美国和dd2中的相应选项,城市:(新德里,孟买),(伦敦,伯明翰),(纽约,华盛顿特区)。我首先选择印度,然后选择孟买,然后选择英格兰,保留孟买,然后添加伦敦。然后,我以类似的方式添加纽约。现在,我意识到我不需要孟买,所以我将其删除,离开了纽约。
尝试失败
我正在尝试将选择附加到先前存在的向量上,并将两个向量的交集传递给“ selected”参数,但这似乎不起作用。我猜测这样做的循环性质可能会导致问题。
基本代码
为了节省您一些时间,并允许我们提供相同的参考-
# server.r
library(shiny)
library(data.table)
countrycity = data.table(
country = c('India','India','England','England','USA','USA'),
city = c('New Delhi','Mumbai','London','Birmingham','New York','Washington DC')
)
shinyServer(function(input, output) {
# dd1: country
output$chooseCountry <- renderUI({
selectizeInput(
"countrSelected",
"Country",
as.list(c('All',unique(unique(countrycity$country)))),
options = list(create = TRUE),
selected = c('All'),
multiple = TRUE,
width="120px"
)
})
# filtering list of cities based on the country selected
citiestoshow = reactive({
countryselected = if ( is.null(input$countryselected) ) {
unique(countrycity$country)
} else if ( 'All' %in% …
Run Code Online (Sandbox Code Playgroud) 有没有办法用自动换行符合某种文字shinydashboard
?默认行为似乎是它溢出到身体区域.
我想避免直接修改css但是如果有一个解决方法涉及修改CSS作为服务器/ ui代码本身的一部分,那么我对此持开放态度.
ui <- dashboardPage(
dashboardHeader(
title = "Sidebar spill"
),
dashboardSidebar(
sidebarMenu(
menuItem(text = "sfsdf sfaosh oas fwue wi aseiu wehw wuer woeur owuer ")
)
),
dashboardBody(
fluidRow(
)
)
)
server <- function(input, output) {
}
shinyApp(ui, server)
}
Run Code Online (Sandbox Code Playgroud) 比较这种行为,
df <- data.frame(a11111 = rnorm(5,0), b11111= rnorm(5,0))
df$a # pressing tab at this instance auto-completes a11111
df$a # hitting return at this instance returns the value for a11111
Run Code Online (Sandbox Code Playgroud)
有这种行为:
library(data.table)
dt <- data.table(df)
dt[,a # pressing tab at this instance does not auto-complete a11111
dt[,a # pressing return at this instance returns an 'object not found' error
dt$a # behaves like how it does for the data frame
Run Code Online (Sandbox Code Playgroud)
我认为返回是有效的,因为x$name
相当于x[["name", exact = FALSE]]
?但是,我不了解自动完成行为.由于data.table
语法基于[ …
我reactiveValues
经常在 Shiny 中使用,因为它们比input
和output
对象更灵活。嵌套的reactiveValues 很棘手,因为任何孩子的任何变化也会触发与父母相关的反应。为了解决这个问题,我尝试制作两个不同的reactiveValues
对象(不是同一个列表中的两个对象,而是两个不同的列表),它似乎正在工作。我找不到任何这样的例子,想知道它是否应该以这种方式工作。是否有任何可能因此出现的问题?
在这个应用程序中,有两个反应值对象 -reac1
和reac2
。他们每个人都与一个下拉,column1
并column2
分别。更改column1
或column2
与最新更新时间的反应值,更新的情节,并在打印的最新值reac1
和reac2
。
ui = fluidPage(
titlePanel("Multiple reactive values"),
sidebarLayout(
sidebarPanel(
selectInput(inputId = "column1", "Reac1", letters, selected = "a"),
selectInput(inputId = "column2", "Reac2", letters, selected = "a")
),
mainPanel(
plotOutput("plot1")
)
)
)
server = function(input, output, session) {
reac1 <- reactiveValues(asdasd = 0)
reac2 <- reactiveValues(qweqwe = 0)
# If any inputs …
Run Code Online (Sandbox Code Playgroud) r ×10
shiny ×4
data.table ×2
ggplot2 ×2
css ×1
facet ×1
font-awesome ×1
merge ×1
rstudio ×1
selectize.js ×1
snowfall ×1