【发布时间】:2020-04-20 06:56:06
【问题描述】:
我正在尝试创建一种用户可以将他们的选择存储为输入的方式。这是我想要完成的示例:
1) 运行应用程序,它会立即生成一个包含三行的表。您可以使用 Sample Label 命名它,例如“Sample1”
2) 点击Save Sample 按钮,然后在我创建的面板中创建一个复选框作为输入,点击该复选框后,将自动将过滤器调整为点击Save Sample 按钮时的样子。
3) 然后将 disp 设置为 160,将 hp 设置为 110,这将返回两行。重复相同的步骤。您将其命名为“Sample2”,然后点击“Save Sample”。现在有两个复选框:Sample1 和 Sample2。您现在可以切换它们,以便用户可以选择他们想要的任何设置。理论上,您可以根据需要多次执行此操作。
library(shiny)
library(shinyWidgets)
ui <- fluidPage(
selectInput("disp", "Disp", choices = unique(sort(mtcars$disp)), selected = 275.8),
selectInput("hp", "hp", choices = unique(sort(mtcars$hp)), selected = 180),
div(style="display:inline-block", textInput(('sample_name'), label = 'Sample Name',width = 200)),
div(style="display:inline-block", actionButton(('select_sample'),icon = icon('save'), label = 'Save Sample')),
panel(h2("User Created Inputs go here")),
DT::dataTableOutput("cardata")
)
server <- function(input,output,session) {
compileData <- reactive({
res <- mtcars %>% filter(hp == input$hp & disp == input$disp)
})
output$cardata <- DT::renderDataTable({
compileData()
})
}
shinyApp(ui,server)
【问题讨论】:
标签: r shiny shiny-server shiny-reactivity shinyapps