R shiny:模态对话中的Timevis输出
R shiny: Timevis output in modal dialogue
如何在 r shiny 的模态对话中显示 timevis 输出。按照 中的示例,我尝试在模式对话中显示时间线。感谢您的帮助。
代码:
library(shiny)
library(timevis)
library(dplyr)
# constructing data frame
pre_data <- data.frame(
group = as.integer(c(1,1,2,2)),
content = c("Item one", "Item two",
"Ranged item", "Ranged item two"),
start = c("2016-01-10", "2016-01-11",
"2016-01-20", "2016-02-14"),
end = c(NA, NA, "2016-02-04", "2016-05-14")
)
# preparing for timevis
data <- pre_data %>%
arrange(group, start) %>%
group_by(group) %>%
mutate(id = row_number())
ui <- fluidPage(
# selectinput getting data from dataframe
selectInput(inputId = "group",
label = "group",
choices = data$group),
timevisOutput("timeline"),
actionButton("show", "Show timeline in modal dialog")
)
server <- function(input, output, session) {
# reactive input variable
var_group <- reactive({input$group})
#
output$timeline <- renderTimevis({
req(var_group())
data %>%
filter(group == as.integer(var_group())) %>%
timevis()
})
observeEvent(input$show, {
showModal(modalDialog(
title = "Important message",
timevisOutput("timeline"),
easyClose = TRUE
))
})
}
shinyApp(ui = ui, server = server)
在此 之后,您可以使用 shinyBS
包中的 bsModal
。我不确定你是否可以在正常的闪亮模式中使用 XOutput
。
library(shiny)
library(timevis)
library(dplyr)
library(shinyBS)
# constructing data frame
pre_data <- data.frame(
group = as.integer(c(1,1,2,2)),
content = c("Item one", "Item two",
"Ranged item", "Ranged item two"),
start = c("2016-01-10", "2016-01-11",
"2016-01-20", "2016-02-14"),
end = c(NA, NA, "2016-02-04", "2016-05-14")
)
# preparing for timevis
data <- pre_data %>%
arrange(group, start) %>%
group_by(group) %>%
mutate(id = row_number())
ui <- fluidPage(
# selectinput getting data from dataframe
selectInput(inputId = "group",
label = "group",
choices = data$group),
actionButton("show", "Show timeline in modal dialog"),
bsModal("timeviesmodal", "Timeline", "show", size = "large",
timevisOutput("timeline"))
)
server <- function(input, output, session) {
# reactive input variable
var_group <- reactive({input$group})
#
output$timeline <- renderTimevis({
req(var_group())
data %>%
filter(group == as.integer(var_group())) %>%
timevis()
})
}
shinyApp(ui = ui, server = server)
如何在 r shiny 的模态对话中显示 timevis 输出。按照
代码:
library(shiny)
library(timevis)
library(dplyr)
# constructing data frame
pre_data <- data.frame(
group = as.integer(c(1,1,2,2)),
content = c("Item one", "Item two",
"Ranged item", "Ranged item two"),
start = c("2016-01-10", "2016-01-11",
"2016-01-20", "2016-02-14"),
end = c(NA, NA, "2016-02-04", "2016-05-14")
)
# preparing for timevis
data <- pre_data %>%
arrange(group, start) %>%
group_by(group) %>%
mutate(id = row_number())
ui <- fluidPage(
# selectinput getting data from dataframe
selectInput(inputId = "group",
label = "group",
choices = data$group),
timevisOutput("timeline"),
actionButton("show", "Show timeline in modal dialog")
)
server <- function(input, output, session) {
# reactive input variable
var_group <- reactive({input$group})
#
output$timeline <- renderTimevis({
req(var_group())
data %>%
filter(group == as.integer(var_group())) %>%
timevis()
})
observeEvent(input$show, {
showModal(modalDialog(
title = "Important message",
timevisOutput("timeline"),
easyClose = TRUE
))
})
}
shinyApp(ui = ui, server = server)
在此 shinyBS
包中的 bsModal
。我不确定你是否可以在正常的闪亮模式中使用 XOutput
。
library(shiny)
library(timevis)
library(dplyr)
library(shinyBS)
# constructing data frame
pre_data <- data.frame(
group = as.integer(c(1,1,2,2)),
content = c("Item one", "Item two",
"Ranged item", "Ranged item two"),
start = c("2016-01-10", "2016-01-11",
"2016-01-20", "2016-02-14"),
end = c(NA, NA, "2016-02-04", "2016-05-14")
)
# preparing for timevis
data <- pre_data %>%
arrange(group, start) %>%
group_by(group) %>%
mutate(id = row_number())
ui <- fluidPage(
# selectinput getting data from dataframe
selectInput(inputId = "group",
label = "group",
choices = data$group),
actionButton("show", "Show timeline in modal dialog"),
bsModal("timeviesmodal", "Timeline", "show", size = "large",
timevisOutput("timeline"))
)
server <- function(input, output, session) {
# reactive input variable
var_group <- reactive({input$group})
#
output$timeline <- renderTimevis({
req(var_group())
data %>%
filter(group == as.integer(var_group())) %>%
timevis()
})
}
shinyApp(ui = ui, server = server)