mrkaye97 / slackr

An R package for sending messages from R to Slack
https://matthewrkaye.com/slackr/
Other
307 stars 85 forks source link

UseMethod("tbl_vars") error #99

Closed surpavan closed 4 years ago

surpavan commented 4 years ago

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.

> dev_slackr(qplot(mpg, wt, data=mtcars))
Error in UseMethod("tbl_vars") : 
  no applicable method for 'tbl_vars' applied to an object of class "NULL"
yonicd commented 4 years ago

Use ggslackr to upload plot outputs as image files to slack

surpavan commented 4 years ago

same error from ggslackr too

yonicd commented 4 years ago

How did you set up the incoming webhook?

slackr::slackr_setup()
slackr::ggslackr(ggplot2::qplot(mpg, wt, data=mtcars),channels = '@yonicd')

Screen Shot 2020-02-25 at 9 09 53 AM

yonicd commented 4 years ago

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.

surpavan commented 4 years ago

@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")
yonicd commented 4 years ago

No offense taken. I’m not familiar with the python implementation, sorry.

surpavan commented 4 years ago

Thank you for the support. I will still be using it since the bot with basic text is working fine. For my R scripts.

surpavan commented 4 years ago

@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
yonicd commented 4 years ago

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

surpavan commented 4 years ago

I am using the '#channel' and also tried with channel id.

yonicd commented 4 years ago

I would need to see the httr response from the internal call that is failing for you in ggskackr to diagnose your issue. Sorry

surpavan commented 4 years ago

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.