0
votes

Is there a way to list the objects(dataframes, functions, args(funtions), inputs, outputs of a shiny app. In the below app, there are inputs likes actionButton(), numericInput() etc, and outputs like renderText(). Is there a way to list these along with there ID'd (eg action Button has "goButton") and so on.

Also, there is a function declared here called "asd" with arguments (3,4). Can we also list these information ? please guide

ui.R

source("fun.R")

pageWithSidebar(
  headerPanel("actionButton test"),
  sidebarPanel(
    numericInput("n", "N:", min = 0, max = 100, value = 50),
    br(),
    actionButton("goButton", "Go!"),
    p("Click the button to update the value displayed in the main panel.")
  ),
  mainPanel(
    verbatimTextOutput("nText")
  )
)

server.R

function(input, output) {

  # builds a reactive expression that only invalidates 
  # when the value of input$goButton becomes out of date 
  # (i.e., when the button is pressed)
  ntext <- eventReactive(input$goButton, {
    input$n
  })

  output$nText <- renderText({
    asd(3,4)
  })
}

fun.R

asd <- function(a,b)
{ 
c <- a + b
return(c)
}
1

1 Answers

0
votes

You can use action buttons, show, hide from shinyjs and verbatimtextoutput to have show code for specific output in your app. Like this:

library(shiny)
library(shinyjs)

asd <- function(a,b)
{ 
  c <- a + b
  return(c)
}

ui <- pageWithSidebar(


  headerPanel("actionButton test"),
  sidebarPanel(
    numericInput("n", "N:", min = 0, max = 100, value = 50),
    br(),
    actionButton("goButton", "Go!"),
    p("Click the button to update the value displayed in the main panel.")
  ),
  mainPanel(

    useShinyjs(),

    tags$head(tags$style("

    #nText {
      color: #333;
      background-color: #f5f5f5;
      border-radius: 4px;');

    }

    pre {
        font-size: 90%;
        color: #c7254e;
        border-radius: 4px;

    }")),

    verbatimTextOutput("nText"),
    actionButton("showtextcode", "Show Code"),
    verbatimTextOutput("textoutputcode"),
    )
)

server <- function(input, output) {

  # builds a reactive expression that only invalidates 
  # when the value of input$goButton becomes out of date 
  # (i.e., when the button is pressed)

  shinyjs::hide("textoutputcode")

  ntext <- eventReactive(input$goButton, {
    input$n
  })

  output$nText <- renderText({
    asd(2,3)
  })

  output$textoutputcode <- renderText({
    "output$nText <- renderText({
        asd(2,3)
})"
  })

  observeEvent(input$showtextcode, {

    if(input$showtextcode %% 2) {
      shinyjs::show("textoutputcode")
    } else {
      shinyjs::hide("textoutputcode")
    }
  }) 


}

shinyApp(ui, server)

Result: enter image description here

If you want to show all of your code for the app, you can create a separate tab that shows the full code placing everything in verbatimTextOutput. However, just because you can doesn't mean you should. For instance, if your shiny app spans 5000 lines then this is a bit silly!

It would be much better to simply include a github link to the source code of the app, if users are interested they can simply follow the link. Remember shiny is designed to share interactive output and not full source code.