【发布时间】:2018-06-11 15:09:58
【问题描述】:
我已经设法构建了一个简单的闪亮应用程序,它从预定义列表中获取用户输入并将此输入作为向量传递给函数,然后输出该函数的结果(这里我用 print 替换了该函数)。
library(shiny)
library(shinythemes)
server <- function(input, output) {
LIST_OF_STUFF = c("A", "B", "C", "D")
other_select <- function(inputId) {
reactive({
select_ids <- grep("^select_\\d+$", names(input), value = T)
other_select_ids <- setdiff(select_ids, inputId)
purrr::map(other_select_ids, purrr::partial(`[[`, input))
})
}
render_select <- function(i, label = "Enter selections") {
renderUI({
this_id <- paste0("select_", i)
this_input <- isolate(input[[this_id]])
selected_elsewhere <- unlist(other_select(this_id)())
available_choices <- setdiff(LIST_OF_STUFF, selected_elsewhere)
selectInput(inputId = this_id, label = label, choices = available_choices,
selected = this_input, multiple = TRUE)
})
}
output$select_1 <- render_select(1)
output$selected_var <- renderTable({
as.data.frame(print(input$select_1))
})
}
ui <- fluidPage(theme = "united",
titlePanel("Title"),
mainPanel(img(src = 'testimage.png', align = "right")),
uiOutput("select_1"),
tableOutput("selected_var"))
shinyApp(ui, server)
几个问题:结果表的标题是“print(input$select_1)”——我该如何自定义它?
我想应用一个主题来为应用添加一些颜色,但它似乎没有显示出来。如何使背景或标题栏着色?
结果表当前在用户选择后立即打印,但我希望它等到用户完成选择输入。我该怎么做?
这是我第一次使用闪亮或制作任何类型的交互式应用程序,如果这些是微不足道的问题,请原谅我。谢谢!
【问题讨论】:
-
请参阅 shiny.rstudio.com/articles/css.html 了解闪亮应用程序的着色。
-
是的,我在脚本中包含了一个主题,但它似乎没有显示。有什么想法吗?
-
theme = shinytheme("united"),你忘了shinytheme参数 -
目前它是一个闪亮的主题。我没有注意到主题和闪亮主题之间有任何区别。