Rで作るShiny Webアプリケーション
Ramnath Vaidyanathan
VP of Product Research

通常はブラウザのUIから受け取るユーザー入力
ui <- fluidPage( titlePanel('Greeting'),textInput('name', 'Enter Name')) server <- function(input, output, session){ } shinyApp(ui = ui, server = server)
ブラウザに表示される出力(例:プロットや表)
`r
ui <- fluidPage( titlePanel('Greeting'), textInput('name', 'Enter Name'), textOutput('greeting') )
----CODE_GLUE---- ```r server <- function(input, output, session){output$greeting <- renderText({ paste("Hello", input$name) })}
ソースに依存し、エンドポイントを更新する中間要素。
server <- function(input, output, session){
output$plot_trendy_names <- plotly::renderPlotly({
babynames %>%
filter(name == input$name) %>%
ggplot(val_bnames, aes(x = year, y = n)) +
geom_col()
})
output$table_trendy_names <- DT::renderDT({
babynames %>%
filter(name == input$name)
})
}
リアクティブ式は遅延評価かつキャッシュされます。
server <- function(input, output, session){
rval_babynames <- reactive({
babynames %>%
filter(name == input$name)
})
output$plot_trendy_names <- plotly::renderPlotly({
rval_babynames() %>%
ggplot(val_bnames, aes(x = year, y = n)) +
geom_col()
})
output$table_trendy_names <- DT::renderDT({
rval_babynames()
})
}
Rで作るShiny Webアプリケーション