# Installation

Detailed installation instructions for all supported platforms.

## Prerequisites

Before you begin, create a free account at [app.gofigr.io/register](https://app.gofigr.io/register).

***

## Python

### Requirements

* Python 3.8 or higher
* pip

### Install via pip

```bash
pip install gofigr
```

This installs both the client library and the IPython extension (compatible with Jupyter, VSCode, and others).

### Configuration

After installation, run the `gfconfig` command-line tool:

```bash
gfconfig
```

This will prompt you for your credentials and save them to `~/.gofigr`.

For advanced options (custom API URL, auto-publish settings, default metadata):

```bash
gfconfig --advanced
```

### Jupyter Usage

The simplest way to use GoFigr in Jupyter is to load the extension:

```python
%load_ext gofigr
```

That's it! All figures you create will be automatically published.

For custom configuration:

```python
%load_ext gofigr

from gofigr.jupyter import configure, FindByName

configure(
    workspace=FindByName("My Workspace"),
    analysis=FindByName("My Analysis", create=True),
    auto_publish=True
)
```

### Script Usage

For standalone Python scripts, use the `Publisher` class:

```python
import matplotlib.pyplot as plt
from gofigr.publisher import Publisher

pub = Publisher(workspace="My Workspace", analysis="Script Analysis")

plt.plot([1, 2, 3], [1, 4, 9])
plt.title("My Plot")

pub.publish(plt.gcf())
```

### Environment Variables

Instead of using `gfconfig`, you can set environment variables:

| Variable          | Description                                     |
| ----------------- | ----------------------------------------------- |
| `GF_USERNAME`     | Your GoFigr username                            |
| `GF_PASSWORD`     | Your GoFigr password                            |
| `GF_API_KEY`      | Your API key (alternative to username/password) |
| `GF_WORKSPACE`    | Workspace API ID                                |
| `GF_ANALYSIS`     | Analysis API ID                                 |
| `GF_URL`          | API URL (default: `https://api.gofigr.io`)      |
| `GF_AUTO_PUBLISH` | `true` or `false`                               |

***

## R

### Requirements

* R 4.0 or higher (tested with R 4.3.2)

### Install from CRAN

```r
install.packages("gofigR")
```

### Install from GitHub (Development Version)

For the latest development version:

```r
library(devtools)
devtools::install_github("gofigr/gofigR")
```

### Configuration

On the R prompt, load the package and run the configuration wizard:

```r
library(gofigR)
gfconfig()
```

This will prompt you for your credentials and save them to `~/.gofigr`.

### R Markdown Usage

In your setup chunk, enable GoFigr:

````markdown
```{r setup, include=FALSE}
library(gofigR)
gofigR::enable()
```
````

You can optionally specify an analysis name:

```r
gofigR::enable(analysis_name = "My Analysis")
```

### Publishing Plots

Use the `publish()` function to capture figures:

```r
library(ggplot2)

# ggplot2
p <- ggplot(mtcars, aes(x = wt, y = mpg)) + geom_point()
publish(p, "Weight vs MPG")

# Or with pipe
p %>% publish("Weight vs MPG")
```

For base R graphics, wrap the plotting code:

```r
publish({
  plot(pressure, main = "Pressure vs Temperature")
  text(200, 50, "Note the non-linear relationship")
}, figure_name = "Pressure Plot")
```

### Shiny Integration

Replace `plotOutput + renderPlot` with `gfPlot + gfPlotServer`:

```r
library(shiny)
library(gofigR)

gofigR::enable()

ui <- fluidPage(
  titlePanel("My App"),
  mainPanel(
    gfPlot("myPlot")
  )
)

server <- function(input, output) {
  gfPlotServer("myPlot", {
    hist(faithful$eruptions, main = "Eruption Duration")
  }, input, figure_name = "Faithful Histogram")
}

shinyApp(ui = ui, server = server)
```

***

## Configuration File

Both Python and R store configuration in `~/.gofigr`. This file is created automatically by the `gfconfig` command/function.

***

## Troubleshooting

### Authentication Errors

If you get authentication errors:

1. Run `gfconfig` again to update your credentials
2. Check that your API key is valid in the GoFigr web app
3. Verify environment variables if using them

### Connection Issues

* Verify you can reach `https://api.gofigr.io`
* Check firewall settings if on a corporate network
* For enterprise installations, ensure `GF_URL` is set correctly

For more help, visit [gofigr.io/support](https://gofigr.io/support).


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.gofigr.io/getting-started/installation.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
