## ----include=FALSE------------------------------------------------------------ knitr::opts_chunk$set( collapse = TRUE, comment = "#>", eval = FALSE ) ## ----------------------------------------------------------------------------- # library(shiny) # library(bslib) # library(shinygenui) # # ui <- page_sidebar( # title = "mtcars explorer", # sidebar = sidebar(width = 380, shinychat::chat_ui("chat", height = "100%")), # genui_canvas("canvas") # ) # # server <- function(input, output, session) { # catalog <- genui_catalog(genui_components_bslib(data = mtcars)) # # genui_server( # "canvas", # catalog = catalog, # chat = ellmer::chat_anthropic(), # data = reactive(mtcars), # chat_id = "chat", # greeting = "Ask me about the mtcars data.", # system_prompt = genui_prompt( # catalog, # context = "The data is the mtcars dataset included with R." # ) # ) # } # # shinyApp(ui, server) ## ----------------------------------------------------------------------------- # histogram <- genui_component( # name = "histogram", # description = "A numeric histogram with a slider for the number of bins.", # args = list( # column = ellmer::type_enum(names(mtcars), "Column to plot."), # bins = ellmer::type_integer("Initial number of bins.", required = FALSE) # ), # ui = function(id, args) { # ns <- shiny::NS(id) # bslib::card( # shiny::plotOutput(ns("plot")), # shiny::sliderInput(ns("bins"), "Bins", 5, 60, args$bins %||% 30) # ) # }, # server = function(id, args, data) { # shiny::moduleServer(id, function(input, output, session) { # output$plot <- shiny::renderPlot({ # hist(data()[[args$column]], breaks = input$bins) # }) # }) # }, # check = function(args, data) { # if (!is.numeric(data[[args$column]])) { # paste0("Column \"", args$column, "\" is not numeric.") # } # } # ) ## ----------------------------------------------------------------------------- # # In the session that built the canvas # observe({ # saveRDS(genui_trace(session)(), "canvas-trace.rds") # }) # # # In a later session, no chat anywhere # server <- function(input, output, session) { # genui_replay( # readRDS("canvas-trace.rds"), # catalog = catalog, # target = "canvas", # data = reactive(mtcars) # ) # }