Closed surpavan closed 4 years ago
Use ggslackr to upload plot outputs as image files to slack
same error from ggslackr too
How did you set up the incoming webhook?
slackr::slackr_setup()
slackr::ggslackr(ggplot2::qplot(mpg, wt, data=mtcars),channels = '@yonicd')
please do not duplicate issues. use the guidance in issue https://github.com/hrbrmstr/slackr/issues/89#issuecomment-497796023. If you still need help use that issue to post questions.
@yonicd No offense, but the same code worked from the slackclient (python). Is there something I am missing. My Code:
> packageVersion("slackr")
[1] ‘1.5.0’
slackr_setup(channel = channel,
username = username,
api_token = api_token,
icon_emoji = "",
incoming_webhook_url=incoming_webhook_url)
slackr('test')
My python code:
client = slack.WebClient(token=api_token)
client.chat_postMessage(channel=channel, text='Test from python')
client.files_upload(channels=channel,file="d:/test.txt")
No offense taken. I’m not familiar with the python implementation, sorry.
Thank you for the support. I will still be using it since the bot with basic text is working fine. For my R scripts.
@yonicd Sorry for being pushing. I tried some code from your ggslackr file and I was able to post the image to slack, but when I do that same from ggslackr call it fails. Could you guide me?
Worked Code:
t = qplot(mpg, wt, data=mtcars)
ftmp <- tempfile('plot', fileext=".png")
ggsave(filename = ftmp, plot = t)
library(httr)
res <- POST(url="https://slack.com/api/files.upload",
add_headers(`Content-Type`="multipart/form-data"),
body=list(file=upload_file(ftmp),
token=api_token,
channels=channel))
res
Error:
> slackr_setup(channel = channel,
+ username = username,
+ api_token = api_token,
+ incoming_webhook_url=incoming_webhook_url)
> ggslackr(t)
Error in fix.by(by.x, x) : 'by' must specify a uniquely valid column
First off not my package or functions.
All credit to @hrbrmstr for writing this up.
it may be how you are passing channel
don't use the slack conversation id or just the naked label of the conversation, it has to be prefixed.
slackr has an internal mechanism for mapping those to the slack conversation id
I am using the '#channel' and also tried with channel id.
I would need to see the httr response from the internal call that is failing for you in ggskackr to diagnose your issue. Sorry
HI @yonicd ,
Thank you for the quick responses. I do not think it is even successfully called the web.
That's fine, since it did not work, but using httr directly worked, I will write my own version for the small requirements I have, see if I can compile it into a module. Will try to make my first module and learn few things from your's and @hrbrmstr code too.
Thank you.
slackr_bot(qplot(mpg, wt, data=mtcars))
sends the command as text and works, but not the image.The below command is throwing error. And the code is copied from the slackr github page.