working on example app

This commit is contained in:
Tom Elliott 2025-01-29 12:02:14 +13:00
parent 6ea0b67993
commit 1907e35fdf
2 changed files with 5 additions and 8 deletions

View File

@ -5,12 +5,12 @@ get_hist <- ts_function(
h <- hist(faithful$waiting, breaks = bins, plot = FALSE) h <- hist(faithful$waiting, breaks = bins, plot = FALSE)
data.frame(x = h$mids, y = h$density) data.frame(x = h$mids, y = h$density)
}, },
result = ts_dataframe(eruptions = ts_numeric(), waiting = ts_numeric()) result = ts_dataframe(x = ts_numeric(0), y = ts_numeric(0))
) )
get_smoother <- ts_function( get_smoother <- ts_function(
function(bandwidth = ts_numeric(1)) { function(bandwidth = ts_numeric(1)) {
d <- density(faithful$waiting, bw = bandwidth) d <- density(faithful$waiting, bw = bandwidth)
data.frame(x = d$x, y = d$y) data.frame(x = d$x, y = d$y)
}, },
result = ts_dataframe(x = ts_numeric(), y = ts_numeric()) result = ts_dataframe(x = ts_numeric(0), y = ts_numeric(0))
) )

View File

@ -34,9 +34,7 @@ source('faithful-app.R')
get_hist$call(10) get_hist$call(10)
``` ```
That's it! We'll use `ts_deploy()` later to create the server code and Typescript schema for the app. That's it! We'll use `ts_compile()` later to create the server code and Typescript schema for the app.
TODO: call ts_compile() from ts_deploy()?
## Create the React app ## Create the React app
@ -57,7 +55,7 @@ pnpm install rserve-ts zod
### Create the server code ### Create the server code
We now use the `ts_deploy()` function to create two files: We now use the `ts_compile()` function to create two files:
- `faithful-app.rserve.R` is the file that will start the Rserve instance with your apps functions available. - `faithful-app.rserve.R` is the file that will start the Rserve instance with your apps functions available.
- `faithful-app.rserve.ts` contains the TypeScript schema (using [zod](https://zod.dev)) that will let you use the R functions directly in the app like any other typescript function! - `faithful-app.rserve.ts` contains the TypeScript schema (using [zod](https://zod.dev)) that will let you use the R functions directly in the app like any other typescript function!
@ -65,8 +63,7 @@ We now use the `ts_deploy()` function to create two files:
We'll send these straight to the `faithful-demo/src` directory. We'll send these straight to the `faithful-demo/src` directory.
```r ```r
ts_compile('faithful-app.R', file = 'faithful-demo/src/faithful-app.rserve.ts') ts_compile('faithful-app.R', filename = 'faithful-demo/src/faithful-app.rserve')
ts_deploy('faithful-app.R', file = 'faithful-demo/src/faithful-app.rserve.R')
``` ```
### Write the app ### Write the app