【发布时间】:2021-12-23 04:35:00
【问题描述】:
我想根据为绘图选择的参数更改框中的文本。让文字和情节同时变化
所以在那个工作示例中:
如果下拉菜单选择 Sepal.width,我希望有 textoutput: "bliblablub"。
如果下拉菜单选择 Sepal.Length,我希望有 textoutput: "some text"。
如果下拉菜单选择 Petal.Length,我希望有文本输出:“完成不同的东西”。
如果下拉菜单选择 Petal.Width,我希望有 textoutput: "new stuff"。
正如我在原始数据框中的 15 个参数中一样,我也希望获得处理每个参数的文本输入的提示。理想情况下,我会从第二个数据框中获取文本(具有相同的列名?)。
到目前为止,我还不明白如何组合选择输入、文本框和绘图框。
非常感谢您的帮助!
library(shiny)
library(shinydashboard)
#data
dat <-iris
#producing parameters for select input
param <- colnames(dat)
param <- param[1:4]
#ui
Header<- dashboardHeader(title = "Iris")
Sidebar <- dashboardSidebar(
sidebarMenu(
menuItem("Parametro", tabName = "parametro", icon = icon("car"))
)
)
Body <- dashboardBody(
tabItems(
tabItem(tabName = "parametro",
column(width = 12,
box(
plotOutput("boxplot_species")),
fluidRow(
box(
selectInput("parametro", "Parametros:",
param), width = 6),
box(
textOutput("description"))
)
))
))
ui <- dashboardPage(Header,
Sidebar,
Body)
server <- function(input, output) {
output$description <- renderText({
"bliblablub"
})
output$boxplot_species <- renderPlot({
ggplot(dat) +
aes(x = Species, fill = Species) +
aes_string(y = input$parametro) +
geom_boxplot()
})
}
shinyApp(ui, server)
【问题讨论】:
标签: r shiny shinydashboard