This function initiates a server for ggfigdone, which can be accessed through a web browser. The web application enables users to manage and modify ggplot figures with ease. Users have the ability to:

  • Update the ggplot code by adding new components.

  • Adjust the figure size.

  • Download the figure as a PDF.

  • Download the data used to create the figure.

fd_server(
  dir,
  host = getOption("ggfigdone.host", "0.0.0.0"),
  port = getOption("ggfigdone.port", 8080),
  llm_api_key = getOption("ggfigdone.llm_api_key", NULL),
  llm_api_url = getOption("ggfigdone.llm_api_url",
    "https://api.openai.com/v1/chat/completions"),
  llm_model = getOption("ggfigdone.llm_model", "gpt-4o-mini"),
  llm_max_tokens = getOption("ggfigdone.llm_max_tokens", 1000),
  llm_temperature = getOption("ggfigdone.llm_temperature", 0.5),
  token = getOption("ggfigdone.token", TRUE),
  auto_open = getOption("ggfigdone.auto_open", FALSE)
)

Arguments

dir

The directory of the ggfigdone database.

host

Server host name or IP address; the default is "0.0.0.0".

port

The port on which the server will run; the default is 8080.

llm_api_key

The API key for the large language model service; the default is NULL. When NULL, the service will not be available.

llm_api_url

The URL for the OpenAI language model; the default is "https://api.openai.com/v1/chat/completions".

llm_model

The model to use for the large language model; the default is "gpt-4o-mini".

llm_max_tokens

The maximum number of tokens to generate; the default is 1000.

llm_temperature

The temperature for the language model; the default is 0.5. The temperature is a hyperparameter that controls the randomness of the generated text. Lower temperatures will generate more predictable text, while higher temperatures will generate more random text.

token

A logical value indicating whether a token should be used to access the server.

auto_open

A logical value indicating whether the server should be opened in a web browser; the default is TRUE.

Value

No return value, the function is called for its side effects.

Details

By default the function will open a web browser to access the server.

You can configure the web browser by setting the options:

options(browser = "firefox")  # Set Firefox as the default

Examples

if (FALSE) {
library(ggplot2)
## Initialize the database
fo = fd_init("./fd_dir")
## Draw a ggplot figure
g = ggplot(mtcars, aes(x=wt, y=mpg)) + geom_point()

## Add the figure to the database
fd_add(name  = "fig1")

## Start the server
fd_server("./fd_dir")
}