要在本地計算機上安裝和配置Shiny Server,請按照以下步驟操作:
1. 安裝R語言:訪問https://cran.r-project.org/下載并安裝適合您操作系統的R版本。
2. 安裝Shiny Server:在R中運行以下命令來安裝Shiny Server包:
install.packages("shiny")
3. 創建一個簡單的Shiny應用:新建一個名為app.R
的文件,并將以下代碼粘貼到文件中:
library(shiny)
ui <- fluidPage(
titlePanel("Hello Shiny!"),
sidebarLayout(
sidebarPanel(
sliderInput("obs", "Number of observations:", min = 0, max = 1000, value = 500)
),
mainPanel(
plotOutput("distPlot")
)
)
)
server <- function(input, output) {
output$distPlot <- renderPlot({
hist(rnorm(input$obs))
})
}
shinyApp(ui = ui, server = server)
4. 啟動Shiny Server:在命令行中,導航到包含app.R
文件的目錄,然后運行以下命令:
R -e "shiny::runApp('.')"
這將啟動Shiny服務器,并在默認端口(通常為3838)上運行您的應用。
5. 訪問Shiny應用:在瀏覽器中輸入http://localhost:3838
,您應該能看到您的Shiny應用已經成功運行。