[英]How to create reactive output from other reactive output in R Shiny App?
Shiny 应用程序 output 的图片。 我想要数据的表在右边
如何在 Shiny 中存储和重用反应数据以进行多个输出?
我想创建另一个 output 显示诸如最有利可图的试验或玩家从该模拟中获得 BJ 的次数百分比等信息。 该代码使用输入来运行我的随机模拟Blackjack function。 我在想我需要存储模拟二十一点()的结果,以便我可以利用数据,我该怎么做?
library(shiny)
ui <- fluidPage(
# Application title
titlePanel("Blackjack 'Perfect Strategy' Simulation"),
sidebarLayout(
sidebarPanel(
numericInput("wager", "How much to wager per hand?", 5,
1, 1000),
sliderInput("hands",
"Number of hands to play:",
min = 1,
max = 1000,
value = 50),
sliderInput("decks",
"Number of decks:",
min = 4,
max = 8,
value = 8),
img(src = "https://wizardofodds.com/blackjack/images/bj_4d_h17.gif", width = 225, height = 600)
),
mainPanel(
dataTableOutput(outputId = "simResults"),
verbatimTextOutput(outputId = "analysis")
)
)
)
server <- function(input, output) {
reactData <- reactive({simulateBlackjack(input$wager,input$hands,input$decks)})
#data <- reactData()
output$simResults <- DT::renderDataTable({
datatable(reactData(), rownames = TRUE, options = list(pageLength = 13, lengthChange = FALSE))
})
# output$analysis <- renderPrint(max(data[13,]))
}
# Run the application
shinyApp(ui = ui, server = server)
尝试这个:
library(shiny)
ui <- fluidPage(
# Application title
titlePanel("Blackjack 'Perfect Strategy' Simulation"),
sidebarLayout(
sidebarPanel(
numericInput("wager", "How much to wager per hand?", 5,
1, 1000),
sliderInput("hands",
"Number of hands to play:",
min = 1,
max = 1000,
value = 50),
sliderInput("decks",
"Number of decks:",
min = 4,
max = 8,
value = 8),
img(src = "https://wizardofodds.com/blackjack/images/bj_4d_h17.gif", width = 225, height = 600)
),
mainPanel(
dataTableOutput(outputId = "simResults"),
verbatimTextOutput(outputId = "analysis")
)
)
)
server <- function(input, output) {
reactData <- reactive({
req(input$wager,input$hands,input$decks)
simulateBlackjack(input$wager,input$hands,input$decks)
})
output$simResults <- DT::renderDataTable({
datatable(reactData(), rownames = TRUE, options = list(pageLength = 13, lengthChange = FALSE))
})
output$analysis <- renderPrint(
max(reactData()[13,])
)
}
# Run the application
shinyApp(ui = ui, server = server)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.