A simple Shiny add-in that connects Gemini 2.0 Flash to RStudio with editor context and multi-turn conversation.
The assistant reads the currently active R script and uses it as context to generate responses to your prompts. It supports multi-turn conversations, making it useful for code debugging, generation, and learning.
- Sends your active R code to Gemini as context (either the whole file or the highlighted section)
- Remembers previous prompts and replies for full conversations
- Uses Shiny Gadgets to integrate directly with the RStudio interface
- Demonstrates API calls, cloud interaction, and RStudio Add-in tooling
Each time you click Generate, the assistant:
- Reads your currently open R script.
- Prepends it to a running conversation history.
- Sends the full prompt to Gemini 2.0 Flash via the Google Generative Language API.
- Displays the assistant's response and updates the conversation.
- R (>= 4.0)
- RStudio
- Packages:
shiny
,httr
,jsonlite
,rstudioapi
You must also set your Gemini API key:
Sys.setenv(GEMINI_API_KEY = "your_api_key_here")
- Run
devtools::install_github("https://github.com/isaacHD-coding/geminiRstudio")
in your RStudio Console. - Run `library(GeminiAssistant) to load the package.
- Run the function
gemini_assistant()
to open the assistant.
- Markdown syntax highlighting sometimes breaks inside the assistant’s response window (e.g. text turns red unexpectedly). This is due to how Shiny renders verbatim text and is a UI limitation rather than a model or API bug.
- The interface is functional but minimal — future improvements could include syntax highlighting, collapsible history, and better formatting.
Contributions welcome.