RAthena | Connect R to Athena using Boto3 SDK | AWS library
kandi X-RAY | RAthena Summary
kandi X-RAY | RAthena Summary
The goal of the RAthena package is to provide a DBI-compliant interface to Amazon’s Athena (using Boto3 SDK. This allows for an efficient, easy setup connection to Athena using the Boto3 SDK as a driver.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of RAthena
RAthena Key Features
RAthena Examples and Code Snippets
library(DBI)
library(dplyr)
con <- dbConnect(RAthena::athena(),
aws_access_key_id='YOUR_ACCESS_KEY_ID',
aws_secret_access_key='YOUR_SECRET_ACCESS_KEY',
s3_staging_dir='s3://path/to/query/bucket/',
library(RAthena)
library(DBI)
con <- dbConnect(RAthena::athena(),
profile_name = "your_profile",
encryption_option = "SSE_S3",
s3_staging_dir='s3://path/to/query/bucket/')
create_work_group(con, "d
query <-
"CREATE EXTERNAL TABLE impressions (
requestBeginTime string,
adId string,
impressionId string,
referrer string,
userAgent string,
userCookie string,
ip string,
number string,
proce
Community Discussions
Trending Discussions on RAthena
QUESTION
I am very new to R. I wanted to use a sql query to get data with R. (I am using athena but I think this doesn't matter).
...ANSWER
Answered 2021-Jan-13 at 15:25You can use function dbGetQuery
from package DBI
From documentation:
Description Returns the result of a query as a data frame. dbGetQuery() comes with a default implementation (which should work with most backends) that calls dbSendQuery(), then dbFetch(), ensuring that the result is always free-d by dbClearResult().
Implemantation from your example:
QUESTION
I am making a shinydashboard app in R. I wanted to make an app that withdraws data from a database in AWS Athena every time it is deployed and display a DT table in my shiny app that gives you the option to see the information based on what date ranges you select in dateInputRange.
I needed an R package for this so I used RAthena
I also used the packages DBI
for the AWS CLI and paws
. I downloaded all what I needed for this like boto3 and so forth. I also made a aws profile that contained all important information like secret key, region, path to bucket etc. Anyways I established a connection to the database and locally I was able to withdraw information from the database. My app was running fine locally. However the app when uploaded to shiny app io and deployed a second time it would not show updated dates in table. I thought this might be due to how I set up the scripts in my app. It now contains three scripts only ui.R, server.R and a global.R
However after I did this I kept getting the error:
Error: Boto3 is not detected please install boto3 using either:
pip install boto3
in terminal orinstall_boto()
. Alternativelyreticulate::use_python
orreticulate::use_condaenv
will have to be used if boto3 is in another environment.
So I did as the error said to and I added:reticulate::use_virtualenv("RAthena")
to my global.R script where all data withdrawals and calculations are done. Here is the stack overflow answer. After I did this I got the error:
Error: Unable to find conda binary. Is Anaconda installed?
I decided to try then reticulate::use_condaenv("RAthena")
I then simply got the boto3 error again. The annoying part is I have checked in my terminal and Boto3 is successfully installed. I also have Anaconda installed I even updated Boto3.
I saw from the answer that it is possible to use noctau
to establish a database connection. I did this and everything worked fine locally. I was able to withdraw data from the database. Of course when I deployed this to shiny app io I got the error
Error in value[3L] : No region provided
I don't know why I have this error. In my aws profile my region for the database is specified. In R studio I see it in the connections tab in the right hand corner.
With the code dbGetInfo(con)
I see it there as well. I don't know what the solution is.
ANSWER
Answered 2020-Nov-07 at 13:19For RAthena it appears shinyapp.io is having difficulty setting up your environment. This tutorial may help solve the RAthena problem. Tutorial: using Shiny + reticulate to create apps with R and Python 3
For noctua, it looks like it is having difficulty getting your aws credentials when on shinyapp.io server. When setting up the shinyapp.io how have you set up your credentials for AWS? Are you using environmental variables or are you using .aws/credentails
and .aws/config
files?
You might want to consider the config
package recommended in the shinyapps.io user guide book: https://docs.rstudio.com/shinyapps.io/applications.html#config-package
Here is an example of how to set it up.
Setting up config.yml
QUESTION
I have an app that I want to deploy on shinyapps.io. I think it is important to note that in the app data is extracted from a database in athena. I used the package Rathena to connect to the database and everything used to run fine locally from my computer. However I tried to deploy it on shinyapps.io and I get a message that an error has occurred. I see this simply in the window that pops up after I deployed it. I went and looked at the log section from shinyapps.io and I see the message that says:
warning: using reticulate but python was not specified; will use python at /usr/bin/python3 Did you forget to set the RETICULATE_PYTHON environment variable in your .Rprofile before publishing?
I have never used an .Rprofile and I don't know what it means by RETICULATE_PYTHON. Anyways they say on stack overflow google is your best friend. I found this tutorial on Github called Tutorial: using Shiny + reticulate to create apps with R and Python 3. I did the initial steps like it says to and then it says at the end:
Confirm that the .Rprofile file is included in your project's directory and was deployed along with server.R and ui.R to shinyapps.io. This file sets the RETICULATE_PYTHON environment variable, which tells reticulate where to locate the Python virtual environment on the shinyapps.io servers.
I looked up what .Rprofile is and I think it's just a script for code but It doesn't tell me what code I should put there. I think I need to mention that package Rathena uses Python code to connect to the database.
I also read somewhere that I should place this line RETICULATE_PYTHON = /usr/local/bin/python3 in my .Renviron file. I did this and now when I try to run the app locally on my computer I get the error message:
Error: Boto3 is not detected please install boto3 using either:
pip install boto3 numpy
in terminal orinstall_boto()
. If this doesn't work please set the python you are using withreticulate::use_python()
orreticulate::use_condaenv()
This doesn't make sense because I already have installed boto3 and even in the terminal it says
Requirement already satisfied: boto3 in ./Library/r-miniconda/envs/r-reticulate/lib/python3.6/site-packages (1.14.28)
I feel like I am going in circles here.
...ANSWER
Answered 2020-Oct-09 at 06:33This is actually a fairly annoying problem with running software locally and running in another environment and I'd say solutions are generally non-obvious. You probably aren't the first person to run into this.
Here are some facts that I think are relevant:
reticulate
needs to know where your Python executable is on the computer- The locatl of the Python executable differs between your computer and the virtual computer shinyapps.io runs your Shiny app from
reticulate
seems to determine where your Python executable is from theRETICULATE_PYTHON
environment variable but also has some default behavior when the variable isn't set- The Python executable on your computer is at a different location than the executable on the virtual computer shinyapps.io runs your Shiny app from
- When you set the value of
RETICULATE_PYTHON
in your.Rprofile
to the value shinyapps.io needs, your setup breaks because your Python environment is different
I haven't tested this as a solution but I think the fix is actually in your link! Check out https://github.com/ranikay/shiny-reticulate-app/blob/master/.Rprofile and see how they include a bit more than just a simple assignment of a value to RETICULATE_PYTHON
and actually use conditional statements to set various values depending on the result of (Sys.info()[['user']]
.
The value of (Sys.info()[['user']]
will differ based upon whether R executes .Rprofile
on your local computer versus the virtual computer shinyapps.io runs your Shiny app on and the linked .Rprofile
is doing the work of setting up various values based upon whether R is running on your local computer or on another computer. This all works because shinyapps.io
From the code in the .Rprofile, I can tell that shinyapps.io runs your Shiny app under the user named "shiny",
QUESTION
I am trying to connect to Athena from R. After setup 'RAthena' and connection, I got this error:
...ANSWER
Answered 2020-Apr-17 at 10:44really sorry to hear you are having issue with the RAthena
package. Can you let me know what version of the package you are running.
Have you tried setting which python you are using through reticulate
? For example:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install RAthena
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page