How to split brilliant application code into multiple files in RStudio?

I tried to split the code for a brilliant application into different files, but I can not get it to work decently in Shiny. My attempt to find in this demo

How can I split my code into different files, but still save the "Run the application" button and get the "Code Completion" in RStudio?

if not! can i integrate brilliant with visual studio?

+6
source share
2 answers

Yes, you can achieve this very easily in the same way as with any other project in RStudio: using the R-mechanisms that provide this:

  • Define functions and / or objects in separate files.
  • ()

RStudio library(shiny). " " . app.R. , RStudio, .

:

app.R :

library(shiny)
source('myUI.R', local = TRUE)
source('myServer.R')


shinyApp(
  ui = myUI,
  server = myserver
)

, myUI myserver .

myUI.R

source('Tabs.R')
myUI <- shinyUI({
  fluidPage(
    tabsetPanel(
      Tab1,
      Tab2
    )
  )
})

UI, app.R. tabsetPanel tabPanels. tabPanels (Tabs.R), UI.

Tabs.R :

Tab1 <- tabPanel("First Tab",
                 selectInput("select",
                             "Choose one",
                             choices = letters[1:3],
                             selected = 'a'))

Tab2 <- tabPanel("Second Tab",
                 textOutput('mychoice'))

tabPanel tabsetPanel. tabPanel .

myServer.R :

myserver <- function(input,output,session){
  output$mychoice <- renderText(
    input$select
  )
}

, , . R: , .

server(). source(..., local = TRUE), server. . : https://shiny.rstudio.com/articles/scoping.html

(, , ), . (. http://shiny.rstudio.com/articles/modules.html)

, app.R.

+8

@Joris Meys . run app, , .

, , , , run app isShinyAppDir, shinyfiletype:

, ui.R, server.R, app.R, global.R, www, ( , . ), 4 run app.

, , , , , reload app, , , reload app .

+1

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


All Articles