闪亮:如何将renderUI()中sliderInput的值集成到renderPlot()中使用的EventResponsive()中
我的闪亮:如何将renderUI()中sliderInput的值集成到renderPlot()中使用的EventResponsive()中,r,plot,shiny,shinyapps,R,Plot,Shiny,Shinyapps,我的app打印一个renderUI(),其中包含一个tabsetPanel(),其中包含一个基于sliderInput()从ui输入$n\u fjernet的绘图 问题 其思想是,renderUI()返回一个名为input$time\u cali的新的sliderInput(),它将所选的滑块值反作用地插入到(…)times=reactive({input$time\u cali})的参数plotCalibration,该参数当前已写入60;和(2),output$cali\u plot应根据o
app
打印一个renderUI()
,其中包含一个tabsetPanel()
,其中包含一个基于sliderInput()
从ui
输入$n\u fjernet
的绘图
问题
其思想是,renderUI()
返回一个名为input$time\u cali
的新的sliderInput()
,它将所选的滑块值反作用地插入到(…)times=reactive({input$time\u cali})的参数plotCalibration
,该参数当前已写入60
;和(2),output$cali\u plot
应根据output$test
如何做到这一点
预期产量
我尝试了times=reactive({input$time\u cali})
和eventReactive()
用
library(shiny)
library(shinyjs)
library(survival)
library(tidyverse)
library(riskRegression)
library(rms)
ui <- fluidPage(
useShinyjs(),
fluidRow(
column(
12,
wellPanel(
style = "height:150px",
sliderInput("n_fjernet", "Lymph Nodal Yield",
min = 4, max = 120, value = 40)
)
),
fluidRow(align="center", br(), actionButton("do", "Submit"),
fluidRow(br(),
column(12,
uiOutput("test")
)
)
)
)
)
server <- function(input, output, session) {
fit_data <- eventReactive(input$do, {
p %>% filter(n_fjernet == as.numeric(input$n_fjernet))
})
reactive_cali_plot <- eventReactive(input$do, {
plotCalibration(Score(list(Nomogram=cph(Surv(os.neck,mors)~alder,
data=fit_data(), y=TRUE, x=TRUE)),
Hist(os.neck,mors)~1,
data=fit_data(),
plots=c("cal"),
times=60, ## This part should be reactively based on input$time_cali from renderUI() in output$test
metrics=c("auc","brier")),
cens.method = "local",
legend.x=.6,
legend.y=.35,
cex=1,
brier.in.legend = TRUE,
auc.in.legend = TRUE)
})
output$cali_plot <- renderPlot({
reactive_cali_plot()
})
observeEvent(input$do, {
output$test <- renderUI({
tabsetPanel(id = "something",
tabPanel(title = "Cali plot",
sliderInput("time_cali", "Months to predict",
min = 12, max = 120, value = 60),
plotOutput("cali_plot",width = "90%", height="650px"))
)
})
})
}
shinyApp(ui, server)
所描述的预期行为有点混乱,但以下是一些可能有用的想法:
- 我会避免将
output
嵌入observeEvent
- 您的
fit_数据
可能只是一个reactive
表达式
plotCalibration
方法只能使用input$time\u cali
- 您可以使用一个简单的
observeEvent
来检测何时按下按钮,然后显示隐藏的sliderInput
和plotOutput
小部件
这更接近你需要的吗
library(shiny)
library(shinyjs)
library(survival)
library(tidyverse)
library(riskRegression)
library(rms)
ui <- fluidPage(
useShinyjs(),
fluidRow(
column(
12,
wellPanel(
style = "height:150px",
sliderInput("n_fjernet", "Lymph Nodal Yield",
min = 4, max = 120, value = 40)
)
),
fluidRow(align="center", br(), actionButton("do", "Submit"),
fluidRow(br(),
column(12,
hidden(tags$div(
id = "hidden_items",
tabsetPanel(id = "something",
tabPanel(title = "Cali plot",
sliderInput("time_cali", "Months to predict",
min = 12, max = 120, value = 60),
plotOutput("cali_plot",width = "90%", height="650px"))
)
))
)
)
)
)
)
server <- function(input, output, session) {
fit_data <- reactive({
p %>% filter(n_fjernet == as.numeric(input$n_fjernet))
})
observeEvent(input$do, {
show("hidden_items")
})
reactive_cali_plot <- reactive({
plotCalibration(Score(list(Nomogram=cph(Surv(os.neck,mors)~alder,
data=fit_data(), y=TRUE, x=TRUE)),
Hist(os.neck,mors)~1,
data=fit_data(),
plots=c("cal"),
times=input$time_cali, ## This part should be reactively based on input$time_cali from renderUI() in output$test
metrics=c("auc","brier")),
cens.method = "local",
legend.x=.6,
legend.y=.35,
cex=1,
brier.in.legend = TRUE,
auc.in.legend = TRUE)
})
output$cali_plot <- renderPlot({
reactive_cali_plot()
})
}
shinyApp(ui, server)
库(闪亮)
图书馆(shinyjs)
图书馆(生存)
图书馆(tidyverse)
图书馆(风险回归)
图书馆(rms)
嗨,本。一如既往地谢谢你。很抱歉,我很难提出我的要求。另一种说法是:我发布的代码实现了我想要的功能,除了当用户更改在output$test
/renderUI()
中打印的名为input$time\u cali
的sliderInput$time\u cali
时,应更新plotCalibration()
中的time
参数,因此,随着time
-参数的更改/更新,plotCalibration()
/output$cali\u plot
相应地更新到新的time=input$time\u cali
,从而生成新的绘图。这有意义吗?是的,非常感谢你的帮助。所以我试过了-但是,当点击actionButton()
时,带有plotOutput
和sliderInput(“时间校准”)的tabsetPanel()
应该会打印出来。然后,在打印时,如果用户更改了input$time\u-cali
,则plotCalibration(time=input$time\u-cali)
会相应地更新,从而生成一个新的绘图,该绘图使用input$time\u-cali
中选择的新指定时间,而sliderInput
应该直接生成新的绘图,而无需按下actionButton()
。因此,当用户更改滑块put
@cmirian查看编辑的答案时,绘图会立即更新。这将显示/隐藏小部件。滑块更改时,绘图应更新。是!这正是我所要求的。谢谢你,我从你身上学到了很多!直到下次:)
library(shiny)
library(shinyjs)
library(survival)
library(tidyverse)
library(riskRegression)
library(rms)
ui <- fluidPage(
useShinyjs(),
fluidRow(
column(
12,
wellPanel(
style = "height:150px",
sliderInput("n_fjernet", "Lymph Nodal Yield",
min = 4, max = 120, value = 40)
)
),
fluidRow(align="center", br(), actionButton("do", "Submit"),
fluidRow(br(),
column(12,
hidden(tags$div(
id = "hidden_items",
tabsetPanel(id = "something",
tabPanel(title = "Cali plot",
sliderInput("time_cali", "Months to predict",
min = 12, max = 120, value = 60),
plotOutput("cali_plot",width = "90%", height="650px"))
)
))
)
)
)
)
)
server <- function(input, output, session) {
fit_data <- reactive({
p %>% filter(n_fjernet == as.numeric(input$n_fjernet))
})
observeEvent(input$do, {
show("hidden_items")
})
reactive_cali_plot <- reactive({
plotCalibration(Score(list(Nomogram=cph(Surv(os.neck,mors)~alder,
data=fit_data(), y=TRUE, x=TRUE)),
Hist(os.neck,mors)~1,
data=fit_data(),
plots=c("cal"),
times=input$time_cali, ## This part should be reactively based on input$time_cali from renderUI() in output$test
metrics=c("auc","brier")),
cens.method = "local",
legend.x=.6,
legend.y=.35,
cex=1,
brier.in.legend = TRUE,
auc.in.legend = TRUE)
})
output$cali_plot <- renderPlot({
reactive_cali_plot()
})
}
shinyApp(ui, server)