Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ospsuite addins #1412

Closed
pchelle opened this issue May 21, 2024 · 12 comments
Closed

ospsuite addins #1412

pchelle opened this issue May 21, 2024 · 12 comments

Comments

@pchelle
Copy link
Contributor

pchelle commented May 21, 2024

RStudio provides an Addins feature that users could leverage when writing scripts.

I drafted below 2 simple functions for potential addins that could be used as starting point for discussing of such features.

Important

Feel free to comment

@pchelle
Copy link
Contributor Author

pchelle commented May 21, 2024

Selecting and copying a unit

Example

image

Code

unitPicker <- function() {
  ui <- miniPage(
    gadgetTitleBar("OSP Unit Picker", left = NULL),
    miniContentPanel(
      selectInput(
        inputId = "dimension",
        label = span(icon("folder-open"), " Dimension"),
        choices = names(ospsuite::ospUnits)
      ),
      selectInput(
        inputId = "unit",
        label = span(icon("folder-tree"), " Unit"),
        choices = as.character(ospsuite::ospUnits$`Abundance per mass protein`)
      ),
      actionButton(
        inputId = "copy",
        label = "Copy",
        icon = icon("copy")
      )
    )
  )

  server <- function(input, output, session) {
    # Update available units based on selected dimension
    observeEvent(input$dimension, {
      updateSelectInput(
        session = session,
        inputId = "unit",
        choices = as.character(ospsuite::ospUnits[[input$dimension]])
      )
    })
    # Copy the unit wrapped with quotes in your current R script position
    observeEvent(input$copy, {
      rstudioapi::insertText(paste0('"', input$unit, '"'))
    })
    observeEvent(input$done, {
      stopApp()
    })
  }

  runGadget(ui, server)
}

@pchelle
Copy link
Contributor Author

pchelle commented May 21, 2024

Get parameter from path by browsing a simulation tree

Example

Step 1 Step 2 Step 3
image image image

Code

simulationPathAddin <- function() {
  # Get object from selected text in RScript
  # Can add validation of the object type at this stage
  selectedText <- rstudioapi::getSourceEditorContext()$selection[[1]]$text
  uiSimulation <- get(selectedText)
  simulationTree <- ospsuite::getSimulationTree(uiSimulation)

  ui <- miniPage(
    gadgetTitleBar("Simulation Test", left = NULL),
    miniContentPanel(
      # Print the selected text and simulation name to check
      htmlOutput("selectedText"),
      htmlOutput("simulationName"),
      br(),
      span(
        icon("square-check"), strong(" Selected Path:"),
        verbatimTextOutput("selectedPath"),
        actionButton(
          inputId = "copy",
          label = "Copy",
          icon = icon("copy")
        ),
        br(),
        span(icon("folder-tree"), " Simulation Tree"),
        # Print simulation paths as an interactive tree leveraging shinyTree package
        shinyTree(
          "tree",
          themeIcons = FALSE,
          themeDots = FALSE,
          theme = "proton"
        )
      )
    )
  )

  server <- function(input, output, session) {
    output$selectedText <- renderPrint({
      span(
        icon("arrow-pointer"),
        " Selected text: ",
        strong(selectedText)
      )
    })
    output$simulationName <- renderPrint({
      span(
        icon("id-card"),
        " Simulation name: ",
        strong(uiSimulation$name)
      )
    })
    
    # Get path from selected shiny tree node
    getPath <- reactive({
      treeNames <- get_selected(input$tree, format = "names")
      if (length(treeNames) == 0) {
        return()
      }
      treeNames <- treeNames[[1]]
      ospsuite::toPathString(attr(treeNames, "ancestry"), treeNames)
    })
    
    output$tree <- renderTree({
      simulationTree
    })
    output$selectedPath <- renderPrint({
      getPath()
    })
    
    # Copy the path wrapped with example text in your current R script position
    observeEvent(input$copy, {
      if (is.null(getPath())) {
        return()
      }
      printedText <- paste0(
        'param <- getParameter("',
        getPath(),
        '", container = ', selectedText, ")"
      )
      rstudioapi::insertText(printedText)
    })

    # When the Done button is clicked, return a value
    observeEvent(input$done, {
      stopApp()
    })
  }

  runGadget(ui, server)
}

@PavelBal
Copy link
Member

Nice! Should we maybe have a separate package ospsuite.addins?

@pchelle
Copy link
Contributor Author

pchelle commented May 23, 2024

Great idea !
This way only the addins will need to support the extra interactive dependencies such as rstudioapi, shiny, shinyTree or miniUI.
And we can centralize in the repo what user would like as addins.

@pchelle
Copy link
Contributor Author

pchelle commented Oct 1, 2024

@PavelBal
Following up on that I drafted a repo with a few addins.

@Yuri05
Copy link
Member

Yuri05 commented Oct 1, 2024

@pchelle Very nice, great enhancements!
@KatrinCoboeken @AnnikaRPS FYI

@PavelBal
Copy link
Member

@Felixmil @rengelke @Laura-Villain

Check this out, especially @Laura-Villain present it to our users? Would it substitute our unit converter?

@pchelle
Copy link
Contributor Author

pchelle commented Oct 16, 2024

@Felixmil @rengelke @Laura-Villain

Check this out, especially @Laura-Villain present it to our users? Would it substitute our unit converter?

The unit converter is now implemented as an addin.

I also forked my repo as an Open-Systems-Pharmacology repo. It'll be more visible to users this way.

@Laura-Villain
Copy link
Contributor

@Felixmil @rengelke @Laura-Villain

Check this out, especially @Laura-Villain present it to our users? Would it substitute our unit converter?

Substitute, I don't know (as in a reproducible code it's always nice to have the option to write a code), but I definitely think that it will help a lot of people that are not super comfortable with R, and I can present that soon
Especially to find the path. @pchelle I don't know if that is too much to ask, but maybe it would be also nice to have a way to search things in path (like getAllParametersMatching but where you can find a keyword like "grep" would do, and not case sensitive?)

@pchelle
Copy link
Contributor Author

pchelle commented Oct 21, 2024

Especially to find the path. @pchelle I don't know if that is too much to ask, but maybe it would be also nice to have a way to search things in path (like getAllParametersMatching but where you can find a keyword like "grep" would do, and not case sensitive?)

The addin: View Simulation Tree / runSimulationTree() allows you to check, select and copy to your keyboard the paths of a pkml simulation file. The shiny app display the paths as a tree and includes a search bar that can be used to search keywords.

@pchelle
Copy link
Contributor Author

pchelle commented Oct 21, 2024

For potential users, I was planning to deploy pkgdown documentation and record in vignettes tutorial videos showing usage of the current addins.

@pchelle
Copy link
Contributor Author

pchelle commented Oct 24, 2024

For new Addins feature requests, let's now use the appropriate Github repo:
https://github.com/Open-Systems-Pharmacology/OSPSuite.Addins/issues

@pchelle pchelle closed this as completed Oct 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants