# Plotting from a server

**URL:** https://discourse.julialang.org/t/plotting-from-a-server/74345
**Category:** General Usage
**Tags:** plotting, gr
**Created:** [January 10, 2022, 5:08pm UTC](https://discourse.julialang.org/t/plotting-from-a-server/74345 "2022-01-10T17:08:14Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![HugoTrentesaux](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hugotrentesaux/32/12583_2.png) [@HugoTrentesaux](https://discourse.julialang.org/u/HugoTrentesaux)
#### Post date: [January 10, 2022, 5:08pm UTC](https://discourse.julialang.org/t/plotting-from-a-server/74345/1 "2022-01-10T17:08:14Z")

</div>

I just opened an issue asking how to use GR without graphical server ([https://github.com/jheinen/GR.jl/issues/442](https://github.com/jheinen/GR.jl/issues/442)) and would like to give a bit of context here. I have a Debian server on which I want to produce automatically some png/svg/plotly-html plots every day using Julia and serve the files with Nginx. However, I encounter a segfault error that seems to be due to the lack of graphical server. Did anybody met the same problem? How to fix it?

---

<div class="post-metadata">

### Author: ![HugoTrentesaux](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hugotrentesaux/32/12583_2.png) [@HugoTrentesaux](https://discourse.julialang.org/u/HugoTrentesaux)
#### Post date: [January 10, 2022, 5:15pm UTC](https://discourse.julialang.org/t/plotting-from-a-server/74345/2 "2022-01-10T17:15:24Z")

</div>

> [@Generation of documentation fails: "qt.qpa.xcb: could not connect to display"](https://discourse.julialang.org/t/generation-of-documentation-fails-qt-qpa-xcb-could-not-connect-to-display/60988/2):
>
> I see you’re using Plots.jl, and “GKS” sounds like the GR backend. In that case, set the magic environmental variable
> 
> ```julia
> ENV["GKSwstype"] = "100"
> 
> ```
> 
> which tells it to operate in “headless” mode where it doesn’t expect an active display connected. (AFAIK this is undocumented but it’s super useful!).

Hum. This definitely _should_ be documented. 😃

---

<div class="post-metadata">

### Author: ![HugoTrentesaux](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hugotrentesaux/32/12583_2.png) [@HugoTrentesaux](https://discourse.julialang.org/u/HugoTrentesaux)
#### Post date: [January 10, 2022, 5:45pm UTC](https://discourse.julialang.org/t/plotting-from-a-server/74345/3 "2022-01-10T17:45:35Z")

</div>

I closed the issue because the `ENV["GKSwstype"] = "100"` solved it, but now, I have a different problem:

When doing in the REPL

```julia-auto
using GR

ENV["GKSwstype"] = "100"

function toto()
    p = histogram(randn(100))
    savefig("fig.png")
end

toto()

```

I get the png output as expected but when I put the previous code in a module `Toto` inside a `Toto.jl` file and call `using Toto; Toto.toto()` from the REPL, I get the segfault again. So now the question becomes: how to make GR aware of environment variables set in a module?

### Answer

The answer I found uses the system environment variables e.g. `export GKSwstype=100` before starting Julia. I would have preferred not to use them and go for a pure Julia fix, but here we are…

---

<div class="post-metadata">

### Author: ![rikh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rikh/32/204104_2.png) [@rikh](https://discourse.julialang.org/u/rikh)
#### Post date: [January 10, 2022, 9:08pm UTC](https://discourse.julialang.org/t/plotting-from-a-server/74345/4 "2022-01-10T21:08:43Z")

</div>

> [@HugoTrentesaux](#):
>
> The answer I found uses the system environment variables e.g. `export GKSwstype=100` before starting Julia. I would have preferred not to use them and go for a pure Julia fix, but here we are…

For what it is worth, the CairoMakie backend for Makie is generally much easier to configure on systems without a GUI. Or UnicodePlots of course

---

<div class="post-metadata">

### Author: ![jheinen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jheinen/32/2787_2.png) [@jheinen](https://discourse.julialang.org/u/jheinen)
#### Post date: [January 11, 2022, 2:02am UTC](https://discourse.julialang.org/t/plotting-from-a-server/74345/5 "2022-01-11T02:02:39Z")

</div>

Please just swap the first two lines:

```julia
ENV["GKSwstype"] = "100"
using GR

```

BTW: It’s documented [here](https://gr-framework.org/workstations.html).
