spanasch commited on
Commit
f7d0bbf
·
1 Parent(s): 952ff27

Add package manager mockup

Browse files
Files changed (3) hide show
  1. app.R +4 -0
  2. package_manager_module.R +140 -0
  3. test_package_manager_app.R +16 -0
app.R CHANGED
@@ -5,6 +5,7 @@ library(commonmark)
5
  library(glue)
6
 
7
  source("llm_api.R")
 
8
 
9
  ui <- fluidPage(
10
  titlePanel("AI-Assisted R Analysis Tool"),
@@ -41,6 +42,7 @@ ui <- fluidPage(
41
  "Display Pane",
42
  plotOutput("display_plot")
43
  ),
 
44
  tabPanel(
45
  "LLM API",
46
  verbatimTextOutput("llm_api_output")
@@ -57,6 +59,8 @@ server <- function(input, output, session) {
57
  last_request <- reactiveVal(NULL)
58
  model <- "llama3-8b-8192" # Replace with your desired model
59
 
 
 
60
  submit_chat <- function() {
61
  req(input$chat_input)
62
 
 
5
  library(glue)
6
 
7
  source("llm_api.R")
8
+ source("package_manager_module.R")
9
 
10
  ui <- fluidPage(
11
  titlePanel("AI-Assisted R Analysis Tool"),
 
42
  "Display Pane",
43
  plotOutput("display_plot")
44
  ),
45
+ packageManagerUI("package_manager"),
46
  tabPanel(
47
  "LLM API",
48
  verbatimTextOutput("llm_api_output")
 
59
  last_request <- reactiveVal(NULL)
60
  model <- "llama3-8b-8192" # Replace with your desired model
61
 
62
+ packageManagerServer("package_manager")
63
+
64
  submit_chat <- function() {
65
  req(input$chat_input)
66
 
package_manager_module.R ADDED
@@ -0,0 +1,140 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # package_manager_module.R
2
+
3
+ # UI function for the Package Manager module
4
+ packageManagerUI <- function(id) {
5
+ ns <- NS(id) # Namespace function to avoid ID collisions
6
+ tabPanel(
7
+ "Package Manager",
8
+ fluidPage(
9
+ # Search Panel with distinct background color
10
+ div(
11
+ style = "background-color: #f7f7f7; padding: 20px; border-radius: 5px; margin-bottom: 20px;",
12
+ fluidRow(
13
+ column(
14
+ width = 12,
15
+ div(
16
+ style = "margin-bottom: 10px;",
17
+ tags$label(
18
+ `for` = ns("task_description"),
19
+ "Description of the task you want to accomplish",
20
+ style = "font-weight: bold; margin-right: 10px; white-space: nowrap;"
21
+ ),
22
+ textInput(
23
+ ns("task_description"),
24
+ label = NULL,
25
+ width = "100%",
26
+ placeholder = "Enter a description of your task..."
27
+ )
28
+ ),
29
+ actionButton(ns("search_button"), "Search Packages", style = "margin-top: 10px;")
30
+ )
31
+ )
32
+ ),
33
+ # Suggestions List
34
+ fluidRow(
35
+ column(
36
+ width = 12,
37
+ h3("Package Suggestions"),
38
+ uiOutput(ns("package_list"))
39
+ )
40
+ )
41
+ )
42
+ )
43
+ }
44
+
45
+ # Server function for the Package Manager module
46
+ packageManagerServer <- function(id) {
47
+ moduleServer(
48
+ id,
49
+ function(input, output, session) {
50
+ ns <- session$ns
51
+
52
+ # Function to get package suggestions (dummy data for now)
53
+ getPackageSuggestions <- function(task_description) {
54
+ # Replace this with actual logic later
55
+ list(
56
+ list(
57
+ name = "ggplot2",
58
+ description = "A system for declaratively creating graphics, based on The Grammar of Graphics."
59
+ ),
60
+ list(
61
+ name = "dplyr",
62
+ description = "A grammar of data manipulation for data transformation and manipulation."
63
+ ),
64
+ list(
65
+ name = "shiny",
66
+ description = "An R package that makes it easy to build interactive web apps straight from R."
67
+ ),
68
+ list(
69
+ name = "data.table",
70
+ description = "An extension of `data.frame` that provides enhanced functionality for fast data manipulation."
71
+ ),
72
+ list(
73
+ name = "tidyr",
74
+ description = paste(
75
+ "Tools for creating tidy data by rectifying the structure of a dataset. Tidy data is a standard way of organizing data values within a dataset,",
76
+ "where every variable is a column, every observation is a row, and every cell is a single value."
77
+ ) # Long description spans multiple lines
78
+ ),
79
+ list(
80
+ name = "caret",
81
+ description = "A set of functions that attempt to streamline the process for creating predictive models."
82
+ )
83
+ )
84
+ }
85
+
86
+ # Reactive value to store package suggestions
87
+ package_suggestions <- reactiveVal(NULL)
88
+
89
+ # Observe the search button to get package suggestions
90
+ observeEvent(input$search_button, {
91
+ task_description <- input$task_description
92
+ # For now, we ignore task_description and use dummy data
93
+ suggestions <- getPackageSuggestions(task_description)
94
+ package_suggestions(suggestions)
95
+ })
96
+
97
+ output$package_list <- renderUI({
98
+ suggestions <- package_suggestions()
99
+ if (is.null(suggestions)) {
100
+ return(NULL)
101
+ }
102
+
103
+ # Generate UI elements for each package suggestion
104
+ suggestion_ui <- lapply(seq_along(suggestions), function(i) {
105
+ pkg <- suggestions[[i]]
106
+ div(
107
+ style = "border: 1px solid #ddd; padding: 10px; margin-bottom: 10px; border-radius: 5px; box-shadow: 2px 2px 5px rgba(0,0,0,0.1); display: flex; justify-content: space-between; align-items: center;",
108
+ div(
109
+ style = "flex-grow: 1;",
110
+ h4(pkg$name, style = "margin: 0;"),
111
+ p(pkg$description, style = "margin: 0;")
112
+ ),
113
+ div(
114
+ style = "flex-shrink: 0;",
115
+ actionButton(ns(paste0("install_", i)), "Install", style = "margin-left: 40px;")
116
+ )
117
+ )
118
+ })
119
+ do.call(tagList, suggestion_ui)
120
+ })
121
+
122
+ # Observe install buttons
123
+ observe({
124
+ suggestions <- package_suggestions()
125
+ if (is.null(suggestions)) {
126
+ return(NULL)
127
+ }
128
+ lapply(seq_along(suggestions), function(i) {
129
+ pkg <- suggestions[[i]]
130
+ install_btn <- paste0("install_", i)
131
+ observeEvent(input[[install_btn]], {
132
+ # For now, we'll just show a notification
133
+ showNotification(paste("Installing package:", pkg$name))
134
+ # Actual installation logic can be added here
135
+ })
136
+ })
137
+ })
138
+ }
139
+ )
140
+ }
test_package_manager_app.R ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # test_package_manager_app.R
2
+
3
+ library(shiny)
4
+
5
+ # Source the module file
6
+ source("package_manager_module.R")
7
+
8
+ ui <- fluidPage(
9
+ packageManagerUI("test_pm")
10
+ )
11
+
12
+ server <- function(input, output, session) {
13
+ packageManagerServer("test_pm")
14
+ }
15
+
16
+ shinyApp(ui, server)