我在R Shiny中创建了以下应用
library(shiny)
library(data.table)
导入库后,我们现在如下创建UI
ui <- fluidPage(
pageWithSidebar(
headerPanel("TestApp"),
sidebarPanel(
numericInput(inputId = "n", label = "N:", min = 0, max = 100, value = 50),
br(),
actionButton(inputId = "goButton", label = "Go!"),
actionButton(inputId = "Reset",label = "Reset")),
mainPanel(dataTableOutput(outputId = "all") ) ))
这将创建一个带有数字输入和两个按钮的ui,一个为执行按钮,另一个为重置按钮
接下来,我们创建服务器并运行App
server <- function(input, output, session) {
table_output<-eventReactive(input$goButton,{ ##### WE CREATE THE TABLE OBJECT HERE
table_output<-data.frame("SLNO"= seq(1:input$n))
table_output$Col2<-table_output$SLNO^2
return(table_output)})
output$all<-renderDataTable({
table_output()})
observeEvent(input$Reset, { #### WE EMPTY THE PLOT AREA HERE
output$all <- renderDataTable({ })})}
shinyApp(ui = ui, server = server)
当我按“执行”按钮时,将生成该表。但是,按下“休息”按钮后,尽管更改了输入,表格仍拒绝渲染。我在这里寻求帮助。
检查是否适合您:
library(shiny)
library(data.table)
ui <- fluidPage(
pageWithSidebar(
headerPanel("TestApp"),
sidebarPanel(
numericInput(inputId = "n", label = "N:", min = 0, max = 100, value = 50),
br(),
actionButton(inputId = "goButton", label = "Go!"),
actionButton(inputId = "Reset",label = "Reset")),
mainPanel(dataTableOutput(outputId = "all") ) ))
server <- function(input, output, session) {
table_output <- eventReactive({input$goButton}, data.frame("SLNO" = seq(1:input$n), "Col2" = seq(1:input$n)^2))
observeEvent(input$goButton, {
output$all <- renderDataTable({
table_output()})
})
observeEvent(input$Reset, {
output$all <- renderDataTable({ })})}
shinyApp(ui = ui, server = server)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句