How do I convert a brilliant multi-file application into an easily accessible and reproducible Shiny example?

There are resources on how to create a minimal, complete, and verified example of an overall stack overflow and how to make a great R reproducible example . However, there are no similar recommendations for questions, while adhering to certain standards makes it much more likely to provide quality answers, and thus your question will be resolved.

However, asking a good, brilliant question can be difficult. applications are often large and complex, use several data sources, and the code is often divided into several files, which makes it difficult to exchange easily reproducible code with others. Although the problem may be caused by server.R, this example does not play without content ui.R(and possibly other files, such as or style sheets global.R). Copying the contents of all these files individually is cumbersome and requires other users to recreate the same file structure in order to be able to reproduce the problem.

So how to convert a shiny application into a good reproducible example?

+24
source share
1 answer

Sample data

, , , " R", , Shiny. : , . , mtcars, data.frame(). , dput(). , read.csv(), , , , , fileInput.

, . .CSS .js ui server.

(ui.R, server.R , , global.R), , . , , , . :

  • ui <- fluidPage(…),
  • server <- function(input,output, session) {…},
  • shinyApp(ui, server).

, :

library(shiny)

ui <- fluidPage(

  )

server <- function(input,output,session) {

}

shinyApp(ui, server)

, , Minimal, Complete Verifiable Shiny- :

library(shiny)

df <- data.frame(id = letters[1:10], value = seq(1,10))

ui <- fluidPage(
  sliderInput('nrow', 'Number of rows', min = 1, max = 10, value = 5),
  dataTableOutput('my_table')
  )

server <- function(input, output, session) {
  output$my_table <- renderDataTable({
    df[1:input$nrow,]
  })
}

shinyApp(ui, server)

CSS

CSS Shiny, . CSS Shiny - CSS , . , ui , , :

tags$head(tags$style(HTML('body {background-color: lightblue;}'))),
+27

Source: https://habr.com/ru/post/1693283/


All Articles