我正在使用R包twitteR将项目发布到Twitter.我把所有东西都放在一个函数中,它工作正常.但是,我想在没有提示响应的情况下运行该函数,我还没想出如何做到这一点.有什么建议?
以下是我的功能:
doit <- function(<snip>) {
<snip>
# connect to Twitter
setup_twitter_oauth(api_key, api_secret, access_token, access_token_secret)
<snip>
}
Run Code Online (Sandbox Code Playgroud)
当我从命令行运行该函数时,系统会提示我进行交互式响应.
[1] "Using direct authentication"
Use a local file to cache OAuth access credentials between R sessions?
1: Yes
2: No
Selection:
Run Code Online (Sandbox Code Playgroud)
当setup_twitter_oauth()函数在函数之外时,我可以通过在以下行中输入我的响应来直接在脚本中提供此信息,这与其他用户输入函数(如readline()或scan())非常相似.
setup_twitter_oauth(api_key, api_secret, access_token, access_token_secret)
1
Run Code Online (Sandbox Code Playgroud)
但是,当setup_twitter_oauth()是函数的INSIDE时,我无法使用此方法.
我将不胜感激任何有关如何在不需要用户输入的情况下运行此建议的建议.
=====
来自@NicE的答案就是诀窍.我将我的功能中的选项设置合并为:
doit <- function(<snip>) {
<snip>
# connect to Twitter
origop <- options("httr_oauth_cache")
options(httr_oauth_cache=TRUE)
setup_twitter_oauth(api_key, api_secret, access_token, access_token_secret)
options(httr_oauth_cache=origop)
<snip>
}
Run Code Online (Sandbox Code Playgroud) 我有一个包含checkboxGroupInput的R Shiny应用程序,我正在尝试使用updateCheckboxGroupInput函数创建一个"全选"按钮.你可以看到下面的完整代码,但基本上我定义了这样的cb组:
checkboxGroupInput("campaigns","Choose campaign(s):",campaigns_list)
Run Code Online (Sandbox Code Playgroud)
然后,在按钮单击时,调用该函数:
updateCheckboxGroupInput(session,"campaigns","Choose campaign(s):",choices=campaigns_list,selected=campaigns_list)
Run Code Online (Sandbox Code Playgroud)
我有一个指示函数运行,但它的作用实际上是取消选中复选框.顺便说一句,当我把选择它放在定义cbGroupInput时它确实有效,但不是在函数上.
谢谢!
这是我的服务器.R:
library(shiny)
source('usefulFunctions.R')
shinyServer(function(input, output, session) {
output$cascading <- renderUI({
provider_id <- input$provider
if (provider_id == "") return(NULL)
campaigns_list <<- t(getCampaigns(provider_id))
tagList(
checkboxGroupInput("campaigns","Choose campaign(s):",
choices = campaigns_list, selected = campaigns_list),
actionLink("selectall","Select All")
)
})
observe({
if(is.null(input$selectall)) return(NULL)
if (input$selectall > 0)
{
print(campaigns_list)
updateCheckboxGroupInput(session,"campaigns","Choose campaign(s):",choices=campaigns_list,selected=campaigns_list)
}
})
})
Run Code Online (Sandbox Code Playgroud) 这不是我的主题,所以如果我的问题被严重询问或数据不完整,我很抱歉.我试图运行31个具有单个响应变量(VELOC)的线性模型,并且预测变量具有因子(TRAT,具有2个级别,A和B)和五个连续变量.
我有一个用于gls但只有连续预测变量的循环,所以我认为它可以工作.但它没有,我相信这个问题一定是个愚蠢的事情.
我不知道如何包含数据,但它看起来像:
TRAT VELOC l b h t m
1 A 0.02490 -0.05283 0.06752 0.03435 -0.03343 0.10088
2 A 0.01196 -0.01126 0.10604 -0.01440 -0.08675 0.18547
3 A -0.06381 0.00804 0.06248 -0.04467 -0.04058 -0.04890
4 A 0.07440 0.04800 0.05250 -0.01867 -0.08034 0.08049
5 A 0.07695 0.06373 -0.00365 -0.07319 -0.02579 0.06989
6 B -0.03860 -0.01909 0.04960 0.09184 -0.06948 0.17950
7 B 0.00187 -0.02076 -0.05899 -0.12245 0.12391 -0.25616
8 B -0.07032 -0.02354 -0.05741 0.03189 0.05967 -0.06380
9 B -0.09047 -0.06176 -0.17759 0.15136 …Run Code Online (Sandbox Code Playgroud) 我是R的新手。我正在尝试通过RMyQL包连接到R中的mySQL。我正在使用以下命令连接到SQL Server
ucscdb<-dbConnect(MySQL(),user="xxxx",password="xxxx",dbname="More",host="http://54.89.81.190/phpmyadmin/").
Run Code Online (Sandbox Code Playgroud)
我收到以下错误
**Error in .local(drv, ...) :
Failed to connect to database: Error: Unknown MySQL Server Host 'http://54.89.81.190/phpmyadmin/' (11001)**
Run Code Online (Sandbox Code Playgroud)
可能是什么原因。同一台SQl服务器很容易在linux /中连接
是否可以按照图的x轴上的值拆分条形图的fill图例ggplot?
例如,使用以下数据:
library(ggplot2)
data <- data.frame(val=c(2,4,5,6,7,8,9),var1=c("A","A","A","B","B","C","C"),
var2=sample(LETTERS[1:7]))
ggplot(data,aes(x=factor(var1),y=val,fill=var2))+geom_bar(stat="identity")
Run Code Online (Sandbox Code Playgroud)
我得到以下情节:

我想要这样的东西,以使其更容易找到每种fill颜色对应的内容:

我有一个数据框,我的第一列是geojson字符串,第二列是该位置的指标.如果粘贴到https://geojson.io/,第一列中的字符串将正确呈现
我想用R中的传单来绘制它,如下面的链接所示.https://rstudio.github.io/leaflet/json.html
不幸的是,我不知道如何将我的数据转换成适用于传单的格式(看似sp对象).
示例数据行:
geojson <- '{"type": "Polygon", "coordinates": [[ [-104.05, 48.99], [-97.22, 48.98], [-96.58, 45.94], [-104.03, 45.94], [-104.05, 48.99] ]]}'
measure1 <- 10000
test_df <- data.frame(geojson, measure1)
test_df$geojson <- as.character(test_df$geojson)
Run Code Online (Sandbox Code Playgroud)
关于这种情况下的最佳实践的任何其他提示也将受到赞赏.
我正在尝试使用 Shiny 中的选项卡编写一个应用程序,该应用程序引用来自文本框的相同输入。
输入:
column(2, textInput(inputId = "sh1", label = "Stakeholder #1's name"))
输出:
tabPanel("#1 vs #2",
fluidRow(
column(3),
column(2, textOutput(outputId = "sh1o")),
column(2, "vs"),
column(2, textOutput(outputId = "sh2o"))
),
tabPanel("#1 vs #3",
fluidRow(
column(3),
column(2, textOutput(outputId = "sh1o")),
column(2, "vs"),
column(2, textOutput(outputId = "sh3o"))
),
Run Code Online (Sandbox Code Playgroud)
渲染:
output$sh1o <- renderText(input$sh1)
据我所知,Shiny 不允许多次使用输入。
有什么办法可以使这项工作?
可以将相同的输入分配给临时变量,然后分配给输出吗?
在玩一些数据帧时,我遇到了一种奇怪的行为:当我创建两个相同的数据帧a,b,然后交换它们的rownames时,它们并不相同:
rm(list=ls())
a <- data.frame(a=c(1,2,3),b=c(2,3,4))
b <- a
identical(a,b)
#TRUE
identical(rownames(a),rownames(b))
#TRUE
rownames(b) <- rownames(a)
identical(a,b)
#FALSE
Run Code Online (Sandbox Code Playgroud)
任何人都可以复制/解释原因吗?
我有一个数据表,带有类似于这个例子的复选框。
复选框是使用 CSS:after和:before伪元素制作的,因此包含它们的列没有值。
当用户单击按钮时,我以编程方式选择一些行,但希望所选行出现在表格顶部。这主要是为了让用户看到正在发生的事情,尤其是当所选行位于不可见页面时。
这是一个小提琴:https : //jsfiddle.net/b22kx27s/2/
我尝试研究自定义排序函数以将所选行置于顶部,但由于该列没有值,因此无法弄清楚如何执行此操作。