Interact. Analyze. Communicate.
Let users interact with your data and your analysis. And do it all with R.
revealjs_presentation is not compatible with runtime 'shiny'
revealjsパッケージははじめからshinyに対応させてないです、はい #japanr
— kazutan (@kazutan) 2018年12月1日
そういうことらしい
薬剤のコンパートメントモデル
薬を投与していい感じの濃度を維持したい
微分方程式を解けば解析的に解は求まる
パラメータをいろいろ変えたい
R を持ってない人にも使ってもらいたい
Shiny 使ったら ?
app.R
内にui
とserver
を用意する
個別にui.R
とserver.R
ファイルを作ってもよい
library(shiny)
# Define UI for application that draws a histogram
ui <- fluidPage(
# Application title
titlePanel("Old Faithful Geyser Data"),
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(sliderInput("bins", "Number of bins:", min=1, max=50, value=30)),
# Show a plot of the generated distribution
mainPanel(plotOutput("distPlot"))
)
)
# Define server logic required to draw a histogram
server <- function(input, output) {
output$distPlot <- renderPlot({
# generate bins based on input$bins from ui.R
x <- faithful[, 2]
bins <- seq(min(x), max(x), length.out=input$bins+1)
# draw the histogram with the specified number of bins
hist(x, breaks=bins, col='darkgray', border='white')
})
}
# Run the application
shinyApp(ui = ui, server = server)
図や表を表示できる
library(shiny)
library(googleVis)
library(ggplot2)
library(plotly)
apropos("^render")
[1] "renderDataTable" "renderGvis" "renderImage" "renderPlot"
[5] "renderPlotly" "renderPrint" "renderTable" "renderText"
[9] "renderUI"
library(googleVis)
dat <- data.frame(year=seq(tsp(Nile)[1], tsp(Nile)[2]), flow=Nile@.Data)
opt <- list(lineWidth=3, width=800, height=300, legend="none",
title="Nile flow", vAxis="{title: 'Flow'}", hAxis="{title:'Year'}")
g <- gvisLineChart(dat, xvar="year", yvar="flow", options=opt)
Rmd ではresults="asis"
でhtml として表示される
土日祝は分娩誘発・帝王切開をしない
20151205japanrhttps://t.co/ssilzmM5Vh @SlideShareさんから
— YF (@Med_KU) 2015年12月5日
スクリプトhttps://t.co/o4nZpOKl1Q#japanr
gganimate
: gifski
がubuntu でうまくいかないのでボツ
aes
plotly
: なんかうまくいった(?)
~
plt <- plot_ly(dataframe, x=~xv, y=~yv, z=~zv, type="heatmap", frame=~frame,
width=560, height=560) %>%
layout( ... ) %>%
animation_opts(frame=300, transition=300, redraw =FALSE)
output$plotly <- renderPlotly( ... )
5つよりたくさん作らないならばshinyapps.io
Rstudio でワンクリックかrsconnect::deployApp
薬剤(フェンタニル)シミュレーション \(\to\) shiny
ワクチンと感染症シミュレーション \(\to\) shiny
インタラクティブなパラメータ操作ができる
プロット結果をそのままブログに使える