我用Shiny中的DT创建了一个数据表,如下所示:

我想在满足某些属性(例如Mfr=Mitsubish、Joint=1等)的侧面板上选择带有复选框的数据然后实时更新deg/s的直方图以查看。
我已经通读了我能在网上找到的材料,但我想不出该怎么做。有谁有什么提示吗?
发布于 2020-03-28 06:11:57
@guero64这里是我的一个例子,我相信它有你正在寻找的例子。我希望这能对你有所帮助。它基于diamonds数据集,并具有两个可应用于数据的checkbox过滤器。
library(shiny)
library(DT)
library(tidyverse)
ui <- shinyUI(pageWithSidebar(
headerPanel("Example"),
sidebarPanel(
checkboxInput("cb_cut", "Cut (Ideal)", FALSE),
checkboxInput("cb_color", "Color (I)", FALSE)
),
mainPanel(
DT::dataTableOutput("data_table"),
plotOutput("data_plot")
)
))
server <- shinyServer(function(input, output) {
filtered_data <- reactive({
dat <- diamonds
if (input$cb_cut) { dat <- dat %>% filter(dat$cut %in% "Ideal") }
if (input$cb_color) { dat <- dat %>% filter(dat$color %in% "I") }
dat
})
output$data_table <- DT::renderDataTable({
filtered_data()
})
output$data_plot <- renderPlot({
hist(filtered_data()$price, main = "Distribution of Price", ylab = "Price")
})
})
shinyApp(ui = ui, server = server)https://stackoverflow.com/questions/60893609
复制相似问题