我的目标是构建一个简单的ShinyApp,它允许用户通过在shiny::textInput
中键入公式(例如x^2
)来在曲线图上显示特定的单变量函数.我试着用ggplot2::stat_funcion
来解决这个问题,但不幸的是,从那以后我一直没能找到解决方案.
My code个
library(tidyverse)
library(plotly)
library(shiny)
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(title = h4(HTML("Title<br/>Subtitle"))),
dashboardSidebar(textInput("function1", "Function")),
dashboardBody(
fluidRow(box(title = h4(HTML("Chart title")),
plotlyOutput("chart", height = 250)))
)
)
server <- function(input, output) {
MyFunction <- function(x) {x}
func <- reactive({MyFunction(input$function1)})
output$chart <- renderPlotly({
ggplotly(
chart = ggplot(data.frame(x = c(0, 15)), aes(x)) +
stat_function(fun = func,
geom = "line", size = 1, show.legend = F) +
scale_x_continuous(limits = c(-100, 100))
)
})
}
shinyApp(ui, server)
我感谢任何帮助!先谢谢你了!