我试图创建一个表,其中包含一些常量值(例如,Cancer_Stage列),然后是React值,当输入发生变化时,React值会立即发生变化。
library(shiny)
library(tidyverse)
library(DT)
df <- dplyr::tibble(Cancer_Stage = c("Localized",
"Regional",
"Distant"),
Costs = c("95",
"24",
"25"))
ui <- fluidPage(
# App title ----
titlePanel("Cancer Stage and Costs"),
# Sidebar layout with input and output definitions ----
sidebarLayout(
# Sidebar panel for inputs ----
sidebarPanel(
# Input: Cost of treatment ----
shiny::textInput(inputId = "Cost_1", label = "Cost Localized"),
shiny::textInput(inputId = "Cost_2", label = "Cost Regional"),
shiny::textInput(inputId = "Cost_3", label = "Cost Distant")
),
# Main panel for displaying outputs ----
mainPanel(
# Output: Histogram ----
DT::DTOutput(outputId = "table")
)
)
)
# Define server logic ----
server <- function(input, output, session) {
mod_df <- shiny::reactiveValues(x = df)
output$table <- DT::renderDT({
isolate(mod_df$x)
})
reactive({
mod_df$x <- mod_df$x %>%
dplyr::bind_rows(
dplyr::tibble(Cancer_Stage = c("Localized",
"Regional",
"Distant"),
Weight = c(input$Cost_1,
input$Cost_2,
input$Cost_3))
)
})
}
shinyApp(ui, server)
我重用了这段代码并取得了一些进步,但是当我改变输入时,表不想更新。谢谢你的帮助!
1条答案
按热度按时间k10s72fa1#
这是否说明了你想做什么?