【发布时间】:2016-03-08 21:28:44
【问题描述】:
在闪亮的应用程序中,我希望每次用户更改绘图类型时标题都是默认标题,但我希望用户能够手动更改文本框中的值并更新绘图标题.基本上这相当于:
规则
1) 每次用户更改下拉菜单中的绘图类型时,使用默认标题并使用标题更新文本框。
2) 每次用户在文本框中进行更改时,将标题替换为文本框中的文本。
举个例子:
1) 如果用户选择绘图类型“n”,则标题将为“绘图类型为 n”,文本框相同。
2) 然后,如果用户在文本框中键入“Blah, blah”,则情节标题变为“Blah blah”。
3) 然后当用户将绘图类型更改为“p”时,标题变为“绘图类型为 p”
等等,建议?
library(shiny)
server <- function(input, output, session) {
output$plot <- renderUI({
h <- input$height
w <- input$width
list(
tags$h3("Plot information"),
renderPlot({
# if input$title has been changed by the user update the
# plot title to input$title, otherwise use default_title
default_title <- paste("Plot type is", input$type)
updateTextInput(session, "title", value=default_title)
plot(1:10, main=default_title, type=input$type)
})
)
})
}
ui <- fluidPage(
tags$div(class="panel-body",
textInput("title", "Give a title", "This is my initital title"),
selectInput("type", "choose type", choices=c("p", "n", "s"), selected="s")
),
uiOutput("plot")
)
shinyApp(ui = ui, server = server)
【问题讨论】:
-
当
selectInput("type")更改时,或者当用户直接在textInput( )框中键入时,您希望绘图标题更改吗? -
感谢您的更新 - 您现在的要求更清楚了。