我已经看到了类似问题的一些解决方案,但它们都需要迭代一起添加的项目数.
这是我的目标:从数字列表中,找到所有组合(无需替换),总计达到一定数量.举例来说,如果我有一个数字1,1,2,3,5和总5,它应该返回5,2,3和1,1,3.
我试图使用,combn但它要求您指定每个组合中的项目数.有没有办法可以实现任何规模的解决方案集?
我想让我的 Shiny 程序的标头通过使用上传的文件名更新自身来对文件输入做出反应。这是我所拥有的:
ui.R:
shinyUI(pageWithSidebar(
headerPanel("File"),
sidebarPanel(
fileInput("file1", "Upload a file:",
accept = c('.csv','text/csv','text/comma-separated-values,text/plain'),
multiple = F) ) ))
Run Code Online (Sandbox Code Playgroud)
服务器.R:
shinyServer(function(input, output, session) {
in_data <- reactive({
inFile <- input$file1
if (is.null(inFile)) return(NULL)
read.csv(inFile$datapath, as.is=T)
}) })
Run Code Online (Sandbox Code Playgroud)
基本上,我想更新 headerPanel,以便在用户上传文件后显示“文件 [名称]”。我在访问 server.R 中的 ui.R 时遇到困难。我尝试在 server.R 中调用 in_data() 但找不到它。有任何想法吗?
我将 global 放在引号中,因为我不希望它可以被 ui.R 访问,而只能通过 server.R 中的每个函数访问。这就是我的意思:
shinyServer(function(input, output, session) {
df <- NULL
in_data <- reactive({
inFile <- input$file1
if (is.null(inFile)) return(NULL)
else df <<- read.csv(inFile$datapath, as.is=TRUE)
return(NULL)
})
output$frame <- renderTable({
df
})
})
shinyUI(pageWithSidebar(
sidebarPanel(fileInput("file1", "Upload a file:",
accept = c('.csv','text/csv','text/comma-separated-values,text/plain'),
multiple = F),),
mainPanel(tableOutput("frame"))
))
Run Code Online (Sandbox Code Playgroud)
我df在shinyServer函数的开头定义了它,并尝试in_data()通过赋值来改变它的全局值<<-。但df永远不会更改其NULL分配(因此 中的输出output$frame仍然是NULL)。有什么方法可以改变dfshinyServer中函数内的总体值吗?然后我想df在 server.R 中的所有函数中用作上传的数据帧,这样我只需调用input$file一次。
我查看了这篇文章,但是当我尝试类似的操作时,抛出了错误,找不到 envir=.GlobalENV 。总体目标是仅调用input$file一次并使用存储数据的变量,而不是重复调用 …
我在Plotly(对于R)做了一个泡泡图,我不断得到重叠的标记.有没有办法"缩小"所有标记,以便保留它们的相对大小,但没有重叠?我想保持情节的尺寸相同.这是一个测试用例:
test <- data.frame(matrix(NA, ncol=3, nrow=14))
colnames(test) <- c("Group", "Numbers", "Days")
loop<- 1
for(i in 1:7){
test[i,] <- c(1, i, loop)
loop <- loop * 1.5
}
loop <- 1
for(i in 1:7){
test[i+7,] <- c(2, i, loop)
loop <- loop * 1.3
}
plot_ly(test, x=Group, y=Numbers, size=Days, mode="markers")
Run Code Online (Sandbox Code Playgroud)