Giter VIP home page Giter VIP logo

rtutor's Introduction

RTutor.ai - Talk to your data via AI

Hosted at RTutor.ai. Contact Steven Ge on LinkedIn or Twitter.

RTutor is an AI-based app that can quickly generate and test R code. Powered by API calls to OpenAI's ChatGPT or other models, RTutor translates natural languages into R scripts, which are then executed within the Shiny platform. An R Markdown source file and HTML report can be generated.

Video tutorial

Highly recommend users to watch this 10-min YouTube video.

What's new

  1. GPT-4 becomes the default, providing more accurate code.
  2. Comprehensive EDA reports.
  3. Chat window that helps explain code, result, error messages, and statistics in general. This makes RTutor a great platform for learning R and statistics.

Installation

This repository is updated frequently, sometimes a few times a day. We suggest users reinstall everytime before using it, so that you always have the most recent version.

  1. Update R and RStudio to the most recent version.
  2. Install the RTutor package
if (!require("remotes")) {
  install.packages("remotes")
}
library(remotes)
#voice input package heyshiny
install_github("jcrodriguez1989/heyshiny", dependencies = TRUE)
install_github("gexijin/RTutor")
  1. Install other R packages. If you want to use additional R package for analyzing your data, you should install these in your computer too.

Obtain an API key from OpenAI

  1. Create a personal account at OpenAI.
  2. After logging in, click on Personal from top left.
  3. Click Manage Account and then Billing, where you can add Payment methods and set Usage limits. $3-$5 per month is more than enough for most people.
  4. Click on API keys to create a new key, which can be copied.

Use the API key with RTutor

There are several ways to do this.

  • After the app is started, you can click on Settings and paste the API key.
  • You can also save this key as a text file called api_key.txt in the working directory.
  • Finally, you can create an environment variable called OPEN_API_KEY. Instructions for Windows, Mac, and Linux.

To start RTutor

library(RTutor)
run_app()

License

(CC BY-NC 3.0) Non-commercial use.

Examples

See this report generated by RTutor after in a typical session.

RTutor also generates comprehensive reports for exploratory data analysis (EDA).

rtutor's People

Contributors

dan-burk avatar gexijin avatar jennathor avatar randef1ned avatar thomuk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

rtutor's Issues

option to change ip address

Hi Steven,

Thank you for developing this wonderful tool.
Currently, RTutor start a shiny using 127.0.0.1:[random port].
I would like to change the IP address but I do not know how to set it.
I tried run_app(port="10.100.128.67") but did not work.

Thank you in advance for your help!
Best Regards,
Martin

shiny is grey and Submit button does not work

I have installed as described. The shiny page opens and looks correct, but it is grey.
"Log", "Ask Me Anything" and "About" react and show the respective tabs.
However, "Submit" doesn't work.
It is running remotely on RStudio server.

API error using new API key structure

I'm encountering an issue with my API key in the Shiny App using the R console in R Studio. When I paste my key into the "Paste your API key from OpenAI" field, I get the error message "That does not look like a valid key!".

I understand that OpenAI has recently updated their API key format to include dashes, underscores, and additional characters. Could the Shiny App's validation be outdated and not recognize the new format?

RTutor only picks up OpenAI key if environment variable set BEFORE installing RTutor

Thanks for helping me solve my previous issue. I managed to make a Dockerfile with RTutor and it works as expected. However, I noticed something that makes it a bit counterintuitive. The launching was perfect if I added the OpenAI key using the 'settings' button on the dashboard. However, if I used an environment variable it worked a bit different to what I expected and makes it a bit more problematic to share my Dockerfile, for instance.

I first installed RTutor, then I created the OPEN_API_KEY environment variable and then launched the dashboard with RTutor::run_app(). However, all my queries failed with an error saying that probably the API key was incorrect. If I added the same API key manually, it worked. After many attempts and looking at the code for a long time, I realized that the OPEN_API_KEY environment variable could only be set up BEFORE installing the RTutor package. If I did that, it worked as expected.

It might not be considered a bug but it could be more of an enhancement. For instance, I would have liked to make a docker image that I can use with different accounts while passing the environment variable at the moment of launching the container (with docker run -e OPEN_API_KEY=<my_api_key> rtutor). However, instead, I had to add the environment variable inside my docker container so that the image itself is bound to my account. If I change accounts, I would need to change the image as well. As said, it is not per se a problem but it could be nicer that the api_key was read at the moment of launching. In any case, this behavior could at least be a bit clearer in your documentation.

Thanks again for this lovely package!

EDA Reports Error

When I try to render an EDA report (EDA -> EDA Reports -> Render Report) I get the error:

"Error when generating the report. Please try again." and the html file isn't generated.

Based on a little debugging it looks like this error occurs when there is less than 2 numeric variables selected in the report. Using the default mpg dataset there are three numeric variables: dis, city, and highway. If at least 2 of these 3 numeric variables aren't selected, the EDA report will not render (Example: if dis is selected, but city and highway are blank we get an error).

error came I just paste the issue

after successfully going through the installation just before finishing it appeared this:

Conflicts ───────────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag() masks stats::lag()
ℹ Use the conflicted package to force all conflicts to become errors

any advise? thank you !

API connection error

H Steven, really great tool!

For some reason I cannot connect my API key. I tried all three methods which are recommended, but it produces the same connection error when I press submit. Any idea how to solve this?

Thanks!

Server performance issues

Sometimes disconnected, unresponsive; even though not many users are on the site. Memory is also not full.

option to fix localhost:port

Hi Steven

Thank you for developing such a cool tool! I'd like to implement it in my research group and therefore install it on one of our servers. To access the site I would do an ssh-tunnel, which allows everybody from my group to access the tool in their own browser.
The problem with that is, that
run_app(port=1234)
does not influence the selected port for the shiny app and hence the tunneling only works, if it is always updated to the currently active port. Is there a way to fix the port upon startup of Rtutor? So far I was not able to find such a config file...

Thank you in advance for your help!

Best,
Christian

A test dataset is loaded but AI generated code Chunk #1 try to work with demo data columns

After entering prompt " Please upload test_data.csv" in the project folder, the AI generated code Chunk #1 is as follows. My test_data.csv, which is supposed to be loaded to df, has its own columns but dis, city, highway from default dataset are still used in the code. The Results section is empty. The EDA also display the default df content. I also tried prompt "Please upload test_data.csv and assign it to df.", the same results. During the process, I used "Reset" button to start from beginning including paste in my API each time. The same happened even if I restarted the app.

Load necessary libraries

library(readr)
library(dplyr)
library(ggplot2)

Load the data

df <- read_csv("test_data.csv")

Summary statistics for numeric variables

summary_stats <- df %>%
select(dis, city, highway) %>%
summary()

Frequency counts for categorical variables

freq_counts <- df %>%
select(maker, model, year, cylinder, transmission, drive, fuel, type) %>%
summarise_all(n_distinct)

Print summary statistics and frequency counts

print(summary_stats)
print(freq_counts)

I then asked it to remove everything from session, here is the AI generated code:

Remove default data from the session

rm(list = ls())

Load necessary libraries

library(readr)
library(dplyr)
library(ggplot2)

Load the data

df <- read_csv("test_data.csv")

Summary statistics for numeric variables

summary(df[, c("dis", "city", "highway")])

Frequency table for categorical variables

lapply(df[, c("maker", "model", "year", "cylinder", "transmission", "drive", "fuel", "type")], table)

Adapting for other LLM apis

Hello! I just found your RTutor and I think it is absolutely brilliant, thank you for developing it! I have been considering ways to integrate R packages with LLM and am thrilled you already made such a robust open-source set up. I am interested in adapting RTutor to utilize alternative APIs such as Gemini, Claude or Llama for NLP and code execution. Have you considered adapting RTutor to support other APIs? I will likely try to do so myself either way, so I would also appreciate any suggestions on approaching this adaptation.

Cannot find RTutor if running inside Docker

Hello! Thanks for making this very nice app! I was testing it today and the installation worked flawlessly in my local computer. However, it is not working inside a docker container. It may be out of the scope of your repo, but I thought maybe you would have an idea on how to fix this issue.

I used the rocker/shiny image as base and this is my Dockerfile. I realized that the run_app() function was using different ports every time so I asked it to use the port = 8050 always.

FROM rocker/shiny:4

RUN R -e "install.packages('remotes', dependencies = TRUE)"
RUN R -e "remotes::install_github('jcrodriguez1989/heyshiny', dependencies = TRUE)"
RUN R -e "remotes::install_github('gexijin/RTutor', dependencies = TRUE)"

RUN useradd -ms /bin/bash RTUTOR
USER RTUTOR

WORKDIR /data

EXPOSE 8050
CMD ["R", "-e", "RTutor::run_app( options = list('port' = 8050) )"]

Then I run the docker image like this, making sure I map the correct ports:

docker build -t rtutor .
docker run  -p 8050:8050 rtutor

Output from docker run:

R version 4.2.2 (2022-10-31) -- "Innocent and Trusting"
Copyright (C) 2022 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> RTutor::run_app( options = list('port' = 8050) )
Loading required package: shiny

Listening on http://127.0.0.1:8050

The app seems to run fine and the output says it is being directed to the right port but I simply cannot find it in my localhost:8050. I have tried changing the way I run it in many different ways, changing the ports, etc., all without avail. I wonder whether you have an idea about how to set it up. Is there something I am missing in the settings? The original docker image comes with some Shiny server that you can run like this

docker run -p 8050:3838 rtutor /init

That one runs without issues in localhost:8050. Any ideas? Thanks and sorry if this is completely out of scope!

Server will become non-responsive, freeze up

Perhaps it is becomes load balancer and worker(docker container with Shiny server) are in the same server with only 4 cores.
There are 30 shiny containers as workers. It is likely 4 of them are at 100% running. Nginx won't be able to get CPU to handline traffic.

Temp. solution:

  1. Increase cores to 8.
  2. Decrease # of containers to 10.

File parsing issues - can't load non-numeric data.

Hi, this is a really interesting tool. Unfortunately, I'm running into some issues using it for "real" data.

I've tried to upload a few files (that are generated from R data.frames via write.table, tab separated), and only the numeric columns are included. Factors are data too!

Here some sample data:
test.txt

When parsed the strings/factors are removed:
image

Additionally, the column names are mutated (and forced to lower case). The original column names:

colnames (df)
[1] "DONOR" "REP_IRVs" "NUM_SNPS" "CENSUS"

Is the API key is correct ERROR

Hi,

Thank you for this amazing app. I have tried to install it locally, and both RStudio and related packages are updated. The shinny app shows up fine, and I have generated my own OpenAI API key, which I have stored in api_key.txt. In the shinny app, I have checked under settings and apparently it is detecting it. However, when running any request, I keep getting this popup error:

"Is the API key is correct?
How about the WiFi?
Maybe the openAI.com website is taking forever to respond."

To the best of my knowledge, the API key is correct. In fact I re-generated a new one just in case. Connectivity is fine and openAI site is responsive. Any other detail that I should pay attention?

----- UPDATE

Actually, if I directly paste my openAI API key, it works fine. However if I store it in the api_key.txt, it does not seem to retrieve it from there. The file is placed under the same directory as the project .Rproj file.

I have tried to store the API key as an environment variable via .zprofile and .zshrc (on zsh shell, default in my MacOS system). It did not work either.

I then tried to store the API key in the global .Renviron file and in that case, when I open Rstudio and type: Sys.getenv("OPEN_API_KEY"), then it shows the value of the key. However for some reason, the shinny app does not seem to retrieve it, or at least it does not appear as such in the 'Current API key' value under the Settings. I did also try to create a local .Renviron file within the same project folder where the shinny app is run, but this it didn't work.

Finally, what I did is to completely download your github code, and manually hardcode my OpenAI API key inside the fct_helpers.R script, as such:

api_key_global <- "sk...." #my openai key

Then I installed my custom package using devtools::install_local() and finally got the shinny app working and keeping always my own API key.

Any suggestions on how to overcome this issue?

Error in if: missing value where TRUE/FALSE needed

Hello,

When trying to start, this is what happens:

run_app()
Listening on http://127.0.0.1:4433
Warning: Error in if: missing value where TRUE/FALSE needed
3: runApp
2: print.shiny.appobj
1:

... The shiny ?container? opens and looks good for about 1 frame. Then it closes immediately, and I don't get control of the console back unless I hit esc in RStudio. I have tried running it in R natively, and it opens to a chrome website. However, the site is immediately greyed out. Same error. I can navigate the website, but I can't submit feedback or query cgpt. I have verified that shiny functions normally. Others with similar shiny issues have reported vaguely server issues, which I'm sure could also be general connection issues. Any idea how I can fix it?

some warning happened and just paste the feedback....

Error :
Warning: The engine_id argument of create_completion() is deprecated as of openai 0.3.0.
ℹ Please use the model argument instead.
ℹ The deprecated feature was likely used in the RTutor package.
Please report the issue to the authors.

Error with some plots although code is correct

Hi again!!

I have been playing with RTutor and I discovered something that I consider a bug. I uploaded a dataset (cannot share because it has sensitive data) and I asked a simple question. The question was this (I changed just col names):

filter patients by “AwesomeValue” in col_1 column. Plot col_2 vs. col_3 and stratify or color points by col_4 column

FYI, the col_1 is a string (could be read as factor), the col_2 and col_3 are numeric and the col_4 is a boolean (containing 1 and 0, so it is read as integer).

The code generated was perfectly fine! I checked it running it myself in an Rmarkdown notebook.

# filter patients by “NSCLC” in cohortnm column
df_AwesomeValue <- df %>%
  filter(col_1 == "AwesomeValue")

# Plot col_2 vs. col_3 mRNA and stratify or color points by col_4 column
ggplot(df_AwesomeValue, aes(x = col_2, y = col_3, color = col_4)) +
  geom_point() +
  labs(x = "col_2", y = "col_3") +
  ggtitle("col_2 vs. col_3 mRNA Stratified by col_4")

However, when RTutor runs it, it fails and I get this error:

Error: An error has occurred. Check your logs or contact the app author for clarification.

When I check the logs on my terminal I see this is the actual error message:

Error in geom_point() : Problem while computing aesthetics.
ℹ Error occurred in the 1st layer.
Caused by error in `FUN()`:
! object 'col_2' not found
Warning: Error in geom_point: Problem while computing aesthetics.

So the tidy evaluation does not seem to work. In your examples, there are other plots that use ggplot2 and use the tidy evaluation also and the objects are properly recognized as being a column. Anyway, not sure whether you manage to reproduce it without having the dataset but happy to explain more or show you by video call if necessary.

shiny error from local install

Just tried running a local install within RStudio and get this error message

/?view=shiny_foreground not found

My details:
R version 4.2.0 (2022-04-22 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19044)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.